indexiatech / ember-forms

Smart, Intuitive forms for Ember.js styled with Bootstrap, Multi layouts and Validation support.
http://indexiatech.github.io/ember-forms
Apache License 2.0
218 stars 45 forks source link

Validation doesn't work for models with relationship #64

Closed e00dan closed 12 months ago

e00dan commented 9 years ago

Validation doesn't work if using 2 em-forms in 1 template. Using model for first model and model.profile for second(user belongs to profile and vice versa). Neither using eg. {{em-input property="profile.firstName"}}. However, values are getting correctly populated here. Only validations doesn't work. My profile model:

`import DS from 'ember-data'`
`import EmberValidations from 'ember-validations'`

Profile = DS.Model.extend
  firstName: DS.attr 'string'
  lastName: DS.attr 'string'
  gender: DS.attr 'string'
  user: DS.belongsTo 'user'

  genderOptions: [
    { id: 'M', name: 'Mężczyzna' }
    { id: 'F', name: 'Kobieta' }
  ]

  validations:
    firstName:
      presence:
        message: 'Imię jest wymagane.'
      length:
        minimum: 2
        maximum: 50
        messages:
          tooShort: 'Imię jest za krótkie.'
          tooLong: 'Imię jest za długie.'

    lastName:
      length:
        maximum: 50
        messages:
          tooLong: 'Nazwisko jest za długie.'

    gender:
      presence:
        message: 'Płeć jest wymagana.'

`export default Profile`
e00dan commented 9 years ago

Actually, this works:

{{#em-form model=model submit_button=false}}
  {{em-input property="name" label="Nazwa konta" placeholder="Podaj nazwę"}}
  {{em-input property="email" label="E-mail" placeholder="Podaj e-mail"}}
  {{em-input property="password" label="Hasło" placeholder="Podaj hasło" type="password" disabled=model.nameAndEmailFilled}}
  {{em-select property="profile.gender" label="Płeć" prompt="Wybierz" contentBinding="model.profile.genderOptions" optionValuePath="content.id" optionLabelPath="content.name"}}
  {{em-checkbox property="rulesAccept" label="Akceptacja regulaminu"}}
  <div class="form-actions">
    <input {{bind-attr disabled=model.isntValid}} {{action 'register'}} type="submit" class="btn btn-default" value="Zarejestruj się"/>
  </div>
{{/em-form}}
{{#em-form model=model.profile submit_button=false}}
  {{em-input property="firstName" label="Imię" placeholder="Podaj imię"}}
{{/em-form}}

But how to use em-input for model.profile.firstName without using second em-form and passing model.profile as it's model?

koryteg commented 9 years ago

+1. nested models would be a super feature