I am currently working with a team on an Ember application which needs form validations. We decided to use ember-cp-validations for the front-end form validations. I am trying to follow the example they have to add some simple validations, but for some reason the validation messages aren't showing. I created a separate file called preprint-form-validator.js which contains the basic validations using buildValidations.
Then in my data model, I imported the file:
import Validations from '../validators/preprint-form-validator';
and extended the model with it so that the model knew that there should be validations for some of its fields:
export default DS.Model.extend(Validations, { ...
After I did that, I followed the example and created the validated-input component. These files can be found here and they create the front-end framework for what the validated form inputs should look like.
Finally, in my component, I included the new validated-input component:
When I go to the page with the validator, there is an input field that doesn't really do anything -- as in it does not validate or check any of the restrictions that I tried to include. In the route that the component is in, I have a model hook that does a createRecord() like this:
import Ember from 'ember';
export default Ember.Route.extend({
model() {
return this.store.createRecord('preprint');
}
});
When I was trying to solve the issue, I believe it's something to do with the model or that somehow the validation property wasn't being set in validated-input.js. However at this point I got stuck and could not figure out what was wrong with my form validation.
It seems like I'm missing some crucial connection in this form validation, but I'm not sure what it is. I would appreciate if anyone could give guidance on what I'm doing wrong.
Aucun commentaire:
Enregistrer un commentaire