jonjamz / blaze-forms

Dead easy reactive forms with validation (Meteor).
https://atmospherejs.com/templates/forms
MIT License
113 stars 11 forks source link

How to manually invalidate a field? #53

Closed steph643 closed 9 years ago

steph643 commented 9 years ago

Here is my use case:

I have this field, where the user has to input the url of an image:

    pictureUrl:
        {
        label: 'Picture URL',
        type: String,
        regEx: SimpleSchema.RegEx.Url,
        max: 500
        }

While the user is typing, in the background, I load the image to see if it of the right dimension (get the result asynchronously). If the result is not good, I would like to manually insert a custom error message in the 'pictureUrl' field.

I tried the following, but it doesn't update the display accordingly:

    var schemaContext = Template.currentData().context.schemaContext;
    schemaContext.addInvalidKeys([{name: 'picture', type: 'notAllowed' }])
steph643 commented 9 years ago

Linked to https://github.com/meteortemplates/forms/issues/51?

steph643 commented 9 years ago

One remark: calling schemaContext.addInvalidKeys() does not update {{valid}} at the element level, but updates {{errorMessage}} at the element level and {{invalidCount}} at the block level.

jonjamz commented 9 years ago

Interesting. I'll have to build in a way to connect the {{valid}} deps to Simple Schema. Shouldn't be too hard.

jonjamz commented 9 years ago

This should be fixed. Please test and let me know. Thanks!

steph643 commented 9 years ago

It works well, except for the fact that it seems {{valid}} now returns false when the form is valid and true when it is not :-)

jonjamz commented 9 years ago

Woops! Should be fixed.

steph643 commented 9 years ago

Works well, thanks!