Skip to content

Instantly share code, notes, and snippets.

@jamesmartin
Created August 23, 2015 01:05
Show Gist options
  • Select an option

  • Save jamesmartin/887b946b66c52522c260 to your computer and use it in GitHub Desktop.

Select an option

Save jamesmartin/887b946b66c52522c260 to your computer and use it in GitHub Desktop.
Stop writing custom forms
new DeclarativeForm({
method: 'POST',
action: '/my-server/does/things/with/forms',
localCsrfToken: 'a7u9k9j87o7kj9j89o9jjk7o',
components: {
name: {
type: 'text', placeHolder: 'Enter your name...', initialValue: '',
validations: { required: true, minLength: 10 }
},
dateOfBirth: {
type: 'date-fields',
validations: { required: true, format: 'DD-MM-YYYY', minimum: Date.parse('1999-01-01') },
postData: { format: { day: "DD", month: "MM", year: "YYYY" } }
},
moveInDate: {
type: 'date-picker',
validations: { required: true, format: 'DD-MM-YYYY', mininmum: "1.week.from_now", maximum: "1.month.from_now" }
},
email: {
type: 'email', placeHolder: 'Supply a valid email address...',
validations: { required: true, uniquenessEndpoint: '/my-server/usernames', uniquenessQuery: '?q=%value%' }
},
phone: {
type: 'mobile-phone', placeHolder: 'Enter a valid Australian mobile number...',
validations: { required: true, prefix: '+61' }
},
currentAddress: {
type: 'address-autosuggest', placeHolder: 'Enter your address...',
validations: { required: true, suggestionEndpoint: '/my-server/address-lookup', suggestionQuery: '?q=%value%' }
}
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment