-
Notifications
You must be signed in to change notification settings - Fork 20
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Document how to add a submit button #57
Comments
This lib is pretty heavily coupled to the html form DOM. So whatever would cause a submit event to fire from Perhaps this could be communicated more clearly? This feels more like html howto stuff though to be honest, which may or may not be under the scope of what the readme should be trying to cover, arguably. Perhaps a good start is to explain that by default the fields are put into the form in the default template, and any submit event that form fires will then be handled by this library? |
For anyone arriving here from searching with the same question, here's my workaround for the meantime. module.exports = FormView.extend({
fields: function () {
return [
new InputView({
label: 'Address',
name: 'address',
value: this.model && this.model.address,
required: false,
placeholder: 'Address',
parent: this
}),
new InputView({
label: 'Capacity',
name: 'capacity',
value: this.model && this.model.capacity,
required: false,
placeholder: 'Capacity',
parent: this
}),
new AmpersandView({
template: '<button type="submit">Submit</button>',
valid: true
})
]
}
}) |
@wraithgar Forgive me, but it's not clear to me how to add a submit button other than the method I've just posted, which is actually giving me some trouble now oddly enough. Are there any alternatives to the approach I posted? |
Ah yes I see now what you mean. The |
Okay I'l give that a shot. I think the reason my example above doesn't work is because the EDIT: Updated code above to add |
I believe you could also use an input-view with type |
FYI I'm trying the approach you described, using a template with a |
Check out this tweak on the readme example: http://esnextb.in/?gist=9d1127976d78d3e17eb4 |
Yes, that's what I was alluding to in my last comment. It looks like the only way to have a submit button is by using the form-view as a subview (or the method I suggested above). In your example, using it as a subview isn't adding much value over just using the form-view as the view. I would suggest that you should be able to just override the module.exports = FormView.extend({
template: '<form><fieldset data-hook="field-container"></fieldset><input type="submit"></form>'
fields: function () {
return [
new InputView({
label: 'Address',
name: 'address',
value: this.model && this.model.address,
required: false,
placeholder: 'Address',
parent: this
}),
new InputView({
label: 'Capacity',
name: 'capacity',
value: this.model && this.model.capacity,
required: false,
placeholder: 'Capacity',
parent: this
})
]
}
}) |
I feel like I must be missing something but I can't find any reference to adding a submit button to a form. There are references to the submit event, which I imagine would be called by hitting enter while an
<input>
is in focus, but that's the closest I see. The only thing I can think of is providing atemplate
to the form view. Is that the only way?EDIT: Looks like the
submitCallback
isn't triggered by hitting enter unless there's a submit button in the form somewhereThe text was updated successfully, but these errors were encountered: