Skip to content

Instantly share code, notes, and snippets.

@andrewheartsxd
Last active January 10, 2018 01:13
Show Gist options
  • Select an option

  • Save andrewheartsxd/352b124a50f15487461aab6b557b0dcf to your computer and use it in GitHub Desktop.

Select an option

Save andrewheartsxd/352b124a50f15487461aab6b557b0dcf to your computer and use it in GitHub Desktop.
ember-bootstrap block form form.element validation
{{#bs-form model=contact onSubmit=(route-action "submitMessage" model) as |form|}}
{{!-- this doesn't work! --}}
{{#form.element label="Email Address" property="email" as |el|}}
<div class="input-group">
<span class="input-group-addon"><i class="fa fa-envelope-o"></i></span>
<input value={{el.value}} class="form-control" oninput={{action (mut el.value) value="target.value"}} id={{el.id}} type="email">
</div>
{{/form.element}}
{{!-- this works! --}}
{{form.element controlType="email" label="Email Address" property="email"}}
{{/bs-form}}
import DS from 'ember-data';
import {validator, buildValidations} from 'ember-cp-validations';
const Validations = buildValidations({
email: [
validator('presence', true),
validator('format', {type: 'email'})
],
message: [
validator('presence', true),
validator('length', {
min: 5
})
]
});
export default DS.Model.extend(Validations, {
email: DS.attr('string'),
message: DS.attr('string')
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment