-
-
Save alexspeller/2feb14a692252816eea8 to your computer and use it in GitHub Desktop.
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
{{#object-form for=this action="formSubmitted" buttonLabel="Click Me" formClass="narrow"}} | |
{{form-field for="email"}} | |
{{form-field for="password" label="Create new password" hint="Minimum 8 characters"}} | |
{{form-field for="passwordConfirmation" label="Confirm new password"}} | |
{{/object-form}} |
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
App.ErrorMessagesComponent = Em.Component.extend | |
errors: Em.computed.filter 'for.errors.content', (error) -> | |
error.attribute != 'base' | |
baseErrors: Em.computed.filter 'for.errors.content', (error) -> | |
error.attribute is 'base' |
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
App.FormFieldComponent = Em.Component.extend | |
type: prop 'for', -> | |
if @get('for').match(/password/) | |
"password" | |
else | |
"text" | |
label: prop 'for', -> | |
@get('for').titleize() | |
fieldId: prop 'object', 'for', -> | |
"#{Em.guidFor @get('object')}-input-#{@get('for')}" | |
isTextArea: Em.computed.equal 'type', 'textarea' | |
object: Em.computed.alias 'parentView.for' | |
hasError: prop 'object.errors.[]', -> | |
@get('object.errors').has @get('for') | |
errors: prop 'object.errors.[]', -> | |
@get('object.errors').errorsFor(@get('for')).mapBy('message').join(', ') | |
# dynamically bind the value field to the right field on the object | |
# needed because the field is provided as a string | |
# This is just to make the api nicer to use, you could pass in both | |
# the string and the value into the component to avoid this magic | |
setupBindings: (-> | |
@binding?.disconnect @ # Disconnect old binding if present | |
# Create a binding between the value property of the component, | |
# and the correct field name on the model object. | |
@binding = Em.Binding.from("object.#{@get 'for'}").to('value') | |
# Activate the binding | |
@binding.connect @ | |
).on('init').observes 'for', 'object' | |
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
App.ObjectFormComponent = Em.Component.extend | |
buttonLabel: "Submit" | |
actions: | |
submit: -> | |
@sendAction() |
wow this looks nice. Great work!
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
If you have bootstrap css this will automatically look pretty good out of the box ;)