jeudi 20 juillet 2017

Emberjs How to Form Validation like jQuery Validation Pluging?

Hi I would like to know if there is a way to create a form validation for diferente model properties for a route like jQuery Validation pluging handles the validations? for example:

My route needs to go first and retrieve some data from a REST API, and then complement the info with extra properties so the template renders the new form.

export default Ember.Route.extend({

userType: Ember.inject.service('user-session'),

model: function (params) {

      return $.getJSON('APIURL', function (data) {


            return {

                  "serverData": data.e.results[0],
                  "id": null,
                  "name": null,
                  "option": 1

             };

      });

   }

});

Then the user changes some info on the form and press the submit button. The problem is, since I do not have any validation the form can be send it by the user with no data.

I used to solve this kind of problems with the jQuery validation plugin creating some rules like:

rules: {
name: {
 required: true
},
id: {
 required: true
}
}, messages: {

  id: { required: 'El campo es requerido (Required in spanish)' }
}

But here on ember.js, I dont know if there is a way to validate the form data.

I have found many plugins that use very basic route models for the examples but since my model is a complex type they dont seem to fit.

Is there any way that I can validate my emberjs forms?




Aucun commentaire:

Enregistrer un commentaire