ember-validated-form
ember-validated-form copied to clipboard
Ember 5.5 Form is not actually validating
Upon using the latest validator and ember packages, it appears as though the form doesn't actually validate. No errors present.
Please advise
Could you give us a little bit more concrete information or in the best case a reproduction repo?
Saying latest
is a relative statement , which could be not the latest already today.
ember version: 5.5 ember-validated-form: ?
You could also clone this repo and link it to you app locally (via pnpm link
) and set a debugger to this line.
Ember version: 5.5 ember-validated-form: 7.0
I will try the debugger if all else fails. Right now it shows all fields, although empty, as valid.
to reiterate, I'm following your example exactly.
Ember version: 4.12 ember-validated-form: 7.0.1
Using ember-cp-validations 6.0.1 which is working correctly but no validate errors show on screen.
// sign-in.js component
import Component from '@ember/component'; import { getOwner } from '@ember/application'; import EmberObject, { set } from '@ember/object'; import { task } from 'ember-concurrency'; import { validator, buildValidations } from 'ember-cp-validations';
const FormModel = EmberObject.extend(buildValidations({ email: { description: 'Email', validators: [ validator('presence', true), ] } }));
export default Component.extend({ init() { this._super(...arguments);
const ownerInjection = getOwner(this).ownerInjection();
set(this, 'formModel', FormModel.create(ownerInjection));
},
taskSubmitForm: task(function* (model) { try { yield model.validate(); // Validate the form if (model.get('validations.isValid')) { // Form is valid, proceed with form submission console.log('Form is valid'); } else { // Form is invalid, handle validation errors console.log('Form is invalid'); } } catch (error) { // Handle validation error console.error('Form validation error:', error); } }).drop(),
});
// sign-in.hbs component
<ValidatedForm @model={{changeset this.formModel}} class="Form--fixedWidth" @validateBeforeSubmit={{true}} @on-submit={{perform this.taskSubmitForm this.formModel}} as |f|>
<f.input @name="email" @type="email" @label="email" @placeholder="[email protected]" @validateBeforeSubmit={{true}} @required={{true}}/>
{{#let f.submit as |Submit|}} <Submit @label={{if f.loading 'Saving...' 'Save'}} @disabled={{f.loading}}/> {{/let}}
@chepworth This addon is based on ember-changeset-validations
. I don't know about the API nor the compatibility of ember-cp-validations
.
@derrabauke I suspect the problem is also evident with ember-changeset-validations as the original ticket was raised by EbonKaiser