Created
December 10, 2009 18:36
-
-
Save JohnB/253551 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
// Each scrap would at least define its inputs, outputs and markup. | |
// Additionally, it would contain any scrap-specific functionality. | |
// Like Rails partials, they could be chained together to build | |
// higher-level functionality. | |
var user_form = Scrap.define({ | |
input: { | |
model: 'hash containing the current state of the user being edited', | |
collection: 'array of all the *other* users, for uniqueness checking', | |
}, | |
output: { | |
model: 'hash containing the updated state of the user being edited' | |
}, | |
markup: [{ | |
div: {id: 'user_form', ui: { | |
table: [ | |
{tr: [ | |
{td: {_class:'field_name', value:'Name'}}, | |
{td: [ | |
{input: {type:'text', id:'name', size:40, | |
value_eval: "input['model']['name']", | |
validation: 'cannot_be_blank_or_duplicate'}}, | |
{span: {id: 'err_msg_for_name', _class:'err_msg'}} | |
]} | |
]}, | |
{tr: [ | |
{td: {_class:'field_name', value:'Password'}}, | |
{td: [ | |
{input: {type:'password', id:'password', size:40, | |
validation: 'password_minimum_length'}}, | |
{span: {id: 'err_msg_for_password', _class:'err_msg'}} | |
]} | |
]}, | |
{tr: [ | |
{td: {_class:'field_name', value:'Confirm Password'}}, | |
{td: [ | |
{input: {type:'password', id:'confirm_password', size:40, | |
validation: 'confirmation_must_match'}}, | |
{span: {id: 'err_msg_for_confirm_password', _class:'err_msg'}} | |
]} | |
]} | |
] | |
}} | |
}], | |
// Assume the original validations have been refactored into the Validate class. | |
cannot_be_blank_or_duplicate: function(field_id) { | |
if( Validate.field_cannot_be_blank(field_id,'Name cannot be blank' ) ) { | |
Validate.field_not_in_list(field_id,collection_names,'Name must be unique' ); | |
}}, | |
password_minimum_length: function(field_id) { | |
Validate.field_minimum_length(field_id,'Password must be at least 3 characters' ); | |
}, | |
confirmation_must_match: function(field_id) { | |
Validate.confirmation(field_id,'password', 'Must match password' ) | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment