type radio with def value, not taking changed value on editor standalone changed mode

type radio with def value, not taking changed value on editor standalone changed mode

perrotinperrotin Posts: 39Questions: 9Answers: 1
edited August 2016 in Editor

Hi,
I'm in trouble with option "changed" of standalone and radio button.
I have one field set with a default value : "portrait" when declared.

The radio button have 2 values : "portrait" and "landscape"

When I'm choosing the "landscape" value, editor send a POST and submit the changed well.

But if landscape was selected and i want to choose "portrait", field is set with "portrait"'s value, but POST wasn't send and value in data base not changed.

When i'm looking in the editor js file, in line 4439, there is this code :

... field.multiSet( idSrc, val !== undefined ? val : field.def() ); ...
If i comment the ligne

field.multiSet( idSrc, val !== undefined ? val : field.def() );

Editor send POST and change value in data base well. But not if the ligne is uncomment.

Is there a bug with "def" value in "changed" mode ? Because it seems "def" value is setting when editor's edit is loading on the field, and a difference between the two value (default and new selected) is made and like value are same, that's not sending POST.

Or have I miss a thing with radio and changed mode from standalone when declare it ?

P.S : same problem with checkbox button.

Best regards

This question has an accepted answers - jump to answer

Answers

  • perrotinperrotin Posts: 39Questions: 9Answers: 1

    I forgort to tell that we're using the editor with edit false option.

    this.editor.edit('row_' + this.ID,false);
    this.editor.set(fieldName,value);
    this.editor.submit();
    
  • allanallan Posts: 63,498Questions: 1Answers: 10,471 Site admin

    Can you try:

    this.editor.edit('#row_' + this.ID,false);
    

    to make it an ID selector please?

    If that doesn't fix it, can you link to the page so I can debug the issue please?

    Thanks,
    Allan

  • perrotinperrotin Posts: 39Questions: 9Answers: 1
    edited September 2016

    Thank you for the answer but it's not working.
    I think it is a Bug but I may be wrong.

    Let me explain again more clearly

    1- We are using an instance editor in ** standalone mode** (no table specified) and server side

    2- We chosed submit option -> submit:"changed"

    3- We got a field with** type :"radio"** and with default def:"myValue" specified

    When we try to programmatically set the value of the field with myValue an ajax call should be send, but it never occures

    I can not give you a link, but you will find here a simple test page that illustrate the bug

    <!DOCTYPE html>
        <head>
            <title>TEST</title>
            <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
            <meta name="robots" content="noindex, nofollow">
    
            <script src="https://code.jquery.com/jquery-1.12.3.js" type="text/javascript"></script>
            <script src="https://cdn.datatables.net/1.10.12/js/jquery.dataTables.min.js" type="text/javascript"></script>
            <script src="_lib/Editor-PHP-1.5.6/js/dataTables.editor.js" type="text/javascript"></script>
    
            <script>
                var editor;
                $(document).ready(function() {
                    editor = new $.fn.dataTable.Editor( {
                        ajax: "/ajax.php",
                        formOptions : {
                            main:{
                                submit : 'changed'
                            }
                        },
                        fields: [
                        {
                            label: "Status:",
                            name:  "radioFieldWithoutDefault",
                            type:  'radio',
                            options: [
                            { label: 'Enabled',  value: 'Enabled' },
                            { label: 'Disabled', value: 'Disabled' }
                            ]
                        },
                        {
                            label: "Status:",
                            name:  "radioFieldWithDefault",
                            type:  'radio',
                            def: "Enabled",
                            options: [
                            { label: 'Enabled',  value: 'Enabled' },
                            { label: 'Disabled', value: 'Disabled' }
                            ]
                        }
                        ]
                    }).on('preSubmit', function( e, data, action ){
                        alert('field submitted to server')
                    });
                    $('.submitRadioWithDefaut').click(function(){
                        editor.edit('row_12',false);
                        editor.set('radioFieldWithDefault','Enabled');
                        editor.submit();
                    })
                    $('.submitRadioWithoutDefaut').click(function(){
                        editor.edit('row_12',false);
                        editor.set('radioFieldWithoutDefault','Enabled');
                        editor.submit();
                    })
                });
        </script>
        </head>
    <html>
    <body>
        <h1>TEST</h1>
        <p>
        Both buttons should trigger an ajax call, but one doesn't
        </p>
        <p>
            <button class="submitRadioWithoutDefaut">submit radio without default</button>
        </p>
        <p>
            <button class="submitRadioWithDefaut">submit radio with default</button>
        </p>
    </body>
    </html>
    
  • allanallan Posts: 63,498Questions: 1Answers: 10,471 Site admin
    Answer ✓

    Thanks for the test case! I think this is actually expected behaviour for the way that Editor is currently setup. The value (because of the default) is "Enabled", and the the field is set to that value again, thus the submit: 'change' sees no change in value and submits nothing.

    The fact that this is standalone without any backing data makes a big difference. When editing a DataTable, the default value is more or less meaningless for an edit action since the value will already exist, and thus the value is used, not the default (default is typically only going to be relevant on create).

    I can see that it perhaps isn't ideal for your use case, but this is the behaviour I would expect Editor to have for this setup.

    You either need to remove the default or use submit: 'all' for such a case.

    Regards,
    Allan

  • perrotinperrotin Posts: 39Questions: 9Answers: 1

    Thanks Allan that's clear now

This discussion has been closed.