[CLOSED] Form Validation with Checkboxgroup

  1. #1

    [CLOSED] Form Validation with Checkboxgroup

    Hi there,

    I have a Formpanel containing many different Fields (Textfields, Textareas, Comboboxes, Radiogroups, ...).

    Only Fields with changes in their value (isDirty flag) are submitted to the server and there is some remote validation, marking invalid Fields.

    After saving I store the form's state by getForm().setValues(values) and by calling markAsValid for each Field.

    This works fine so far but I encounter a problem with selected checkboxes for the setValues() function. They are keeping getting unchecked after the setValues() call:

    <!DOCTYPE html>
    <html>
    <head>    
        <meta charset="utf-8" />
        <script type="text/javascript"">
            function markFormPanelValid(formPanel) {
    
                formPanel.cascade(function (f) {
                    if (f.clearInvalid) {
                        f.clearInvalid();
                    }
                });
    
                formPanel.getForm().setValues(formPanel.getForm().getValues());
            }
        </script>
    </head>
    <body>
    
        @Html.X().ResourceManager()    
    
        @(Html.X().FormPanel()
            .ID("FormPanel")
            .Layout(LayoutType.Form)
            .Title("FormPanel")
            .TrackResetOnLoad(true)
            .Buttons(
                Html.X().Button().Text("Set Dirty").OnClientClick("App.Item_457.markInvalid('invalid');"),
                Html.X().Button().Text("Clear").OnClientClick("markFormPanelValid(App.FormPanel);")
            )
            .Items(
                Html.X().CheckboxGroup().ID("Item_456").Items(
                    Html.X().Checkbox().Name("Item_456").BoxLabel("Input 1").InputValue("1").UncheckedValue("-1"),
                    Html.X().Checkbox().Name("Item_456").BoxLabel("Input 2").InputValue("2").UncheckedValue("-2"),
                    Html.X().Checkbox().Name("Item_456").BoxLabel("Input 3").InputValue("3").UncheckedValue("-3"),
                    Html.X().Checkbox().Name("Item_456").BoxLabel("Input 4").InputValue("4").UncheckedValue("-4")
                ),
            
                Html.X().TextField().ID("Item_457")
            )
        )
            
    </body>
    </html>
    Is there a workaround for the checkboxes?
    Last edited by Daniil; Aug 27, 2013 at 3:44 AM. Reason: [CLOSED]
  2. #2
    Hi @extnetuser,

    Yes, there is some inconsistency in that part of API.

    I can suggest the following workaround.

    function markFormPanelValid(formPanel) {
        var originalSetValue = Ext.form.CheckboxGroup.prototype.setValue;
     
        formPanel.cascade(function (f) {
            if (f.clearInvalid) {
                f.clearInvalid();
            }
    
            if (f.is('checkboxgroup')) {
                f.setValue = Ext.emptyFn;
            }
        });
     
        formPanel.getForm().setValues(formPanel.getForm().getValues());
    
        formPanel.cascade(function (f) {
            if (f.is('checkboxgroup')) {
                f.setValue = Ext.originalSetValue;
            }
        });
    }
  3. #3
    Thank you @ Daniil, thread can be marked as closed.

Similar Threads

  1. [CLOSED] V2.0 Validation Form Help
    By Aurelio in forum 2.x Premium Help
    Replies: 2
    Last Post: Mar 14, 2012, 2:55 PM
  2. form validation problem
    By ozayExt in forum 1.x Help
    Replies: 1
    Last Post: Oct 27, 2011, 7:05 AM
  3. Login form - validation form
    By LordMX in forum 1.x Help
    Replies: 0
    Last Post: Aug 14, 2011, 11:44 AM
  4. [CLOSED] validation form all
    By rnfigueira in forum 1.x Premium Help
    Replies: 1
    Last Post: Mar 22, 2011, 8:05 PM
  5. Replies: 1
    Last Post: Mar 24, 2010, 1:44 PM

Tags for this Thread

Posting Permissions