Force re-validation in jsViews if data-linked value doesn't change

410 views Asked by At

I ran into an issue while using jsViews with validation (using code from jsviews.com/#samples) and jQuery UI Autocomplete:
I have a converter (convertBack) on the field that transforms the entered text back into a GUID based on a dictionary. It returns null if the field is empty or invalid.

The issue is that jsViews doesn't notice the update from one null value to the other (i.e. blank to invalid, and vice versa). I tried to fix this by adding a call to refreshValidates() on the validation tag to the DOM onChange manually, but any invalid value entered gets deleted.

Question: Is there a way to achieve re-validation in jsViews natively?

I changed the jsViews validation code to allow checking displayed value:
[End of onAfterLink]: It passes the current (displayed) value, not only the converted (which is null in both cases):

 (...)
    tag.validate(tagCtx.args[0], tag.linkedElem.val()); // Validate initial data
1

There are 1 answers

6
BorisMoore On BEST ANSWER

tag.linkedElem is the HTML element on which you are doing 2-way data-binding, (and validation).

So if you just want to get the current value of the input element, yes, tag.linkedElem.val() is good.

Additional response added following your comment below:

Looking at your jsfiddle: http://jsfiddle.net/w43hD/1/

You are using

data-link="{validate DictionaryValue inDictionary='dictionary' convert='fromGuid' convertBack='toGuid'}"

which will trigger validation when the DictionaryValue it is binding to changes. But you are mapping both invalid user entry strings and the empty string to the same DictionaryValue of null. So of course switching from invalid to empty string does not trigger validation.

You can change your getKey converter to map the empty string to something other than null, e.g. "" - and then it works. See updated version: http://jsfiddle.net/w43hD/2/