Created
March 1, 2011 21:10
-
-
Save insin/849904 to your computer and use it in GitHub Desktop.
Tonight's coding mission: implement deep copying to kill some rather ugly boilerplate
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// From... | |
var TestForm = forms.formFactory({ | |
fields: function() { | |
return { | |
username: new forms.CharField(), | |
password: new forms.CharField({widget: forms.PasswordInput}) | |
}; | |
}, | |
clean: function() { | |
if (this.cleanedData.username && this.cleanedData.password && | |
(this.cleanedData.username != 'admin' || | |
this.cleanedData.password != 'secret')) { | |
throw new forms.ValidationError('Invalid credentials!'); | |
} | |
return this.cleanedData; | |
} | |
}); | |
// ...to... | |
var TestForm = forms.formFactory({ | |
username: new forms.CharField(), | |
password: new forms.CharField({widget: forms.PasswordInput}), | |
clean: function() { | |
if (this.cleanedData.username && this.cleanedData.password && | |
(this.cleanedData.username != 'admin' || | |
this.cleanedData.password != 'secret')) { | |
throw new forms.ValidationError('Invalid credentials!'); | |
} | |
return this.cleanedData; | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment