Forums

Home » Alloy UI » English

Combination View Flat View Tree View
Threads [ Previous | Next ]
toggle
bo li
How to "DISABLE" the validator after bound to a field?
November 6, 2012 7:12 AM
Answer

bo li

Rank: Junior Member

Posts: 34

Join Date: November 14, 2011

Recent Posts

A question about AUI form and AUI validator. Q: How to "DISABLE" the validator after bound to a field?
Context:
When the form loads, there is a selection box of option1 option2, option3, and hidden fields field1, field2, field3.
1.Select "option1", input field "field1" will show up, and bound with A.FormValidator( required:true).
2.Select "option2", input field "field1" will be hidden, "field2" will show up.
At this point, I set the validator for "field1" required:false. But it is still required.

I think the form can't be sent to the server to change required:false. Is there a solution for this? Thanks in advance!
Pavel Savinov
RE: How to "DISABLE" the validator after bound to a field?
November 7, 2012 12:23 AM
Answer

Pavel Savinov

Rank: Junior Member

Posts: 97

Join Date: September 24, 2012

Recent Posts

Hi!

Here some kind of working solution of that problem, but i'm sure that there should be something more elegant:
 1<form id="someForm">
 2    <input type="text" name="someField" id="someField2"/>
 3    <button type="submit" value="submit"/>
 4    <button type="button" onclick="cancelValidation('someField2');" value="no-validation"/>
 5</form>
 6
 7<aui:script>
 8function cancelValidation(fieldId) {
 9    AUI().ready('aui-form-validator',
10        function (A) {
11        var v = A.one("#someForm").validatorObject;
12        v.on("validateField", function (event) {
13            for (var k in event.details) {
14                var name = event.details[k].validator.field;
15                if (name.lastIndexOf("#" + fieldId) != -1) {
16                    event.halt();
17                    break;
18                }
19            }
20        });
21    });
22}
23
24AUI().ready('aui-form-validator',
25    function (A) {
26    var v = new A.FormValidator({
27            boundingBox : '#someForm',
28            rules : {
29                someField : {
30                    required : true
31                }
32            }
33        });
34    A.one("#someForm").validatorObject = v;
35   
36});
37</aui:script>
bo li
RE: How to "DISABLE" the validator after bound to a field?
November 7, 2012 6:52 AM
Answer

bo li

Rank: Junior Member

Posts: 34

Join Date: November 14, 2011

Recent Posts

Thank you for your solution, I am using the similar way to do it, event.hault() to prevent the event from happening.