Editor fires event on form load

Editor fires event on form load

piq_pm_pjkpiq_pm_pjk Posts: 21Questions: 7Answers: 1

debugger code: etaqiw

Hello,

I have a form that when opened from the tabletools 'new' button fires some of our event listeners twice.

For example:

    $('input', editor.node('part_master.part_number')).on('change', function () {
        alert("this should fire only on change");
    } ) ;

I added the above snippet in the shipments.js file, between the editor portion and the datatables portion. It fires twice, when the input form is opened. It accurately alerts the text when the part_master.part_number field gets changed as expected.

Part 2)

I have a jqueryui datepicker on the top of the form. i can add a default text, but the datepicker popout opens on form load. Is there a way to not display the datepicker popout when the form loads. Only when the user clicks on the field or graphic.

        fields: [ {

            label: 'Ship Date:',
            name: 'shipments.ship_date',
            type: 'date',
            def: function () { return new Date(); },
            dateFormat: 'yy-mm-dd',
            dateImage: 'tables/DataTables-1.10.0/media/images/calendar.png'
                        
            }  // more code continues after this

This question has an accepted answers - jump to answer

Answers

  • allanallan Posts: 63,679Questions: 1Answers: 10,498 Site admin

    Hi,

    1) The change event will be triggered when the form is shown initially as the fields value is changed (to the default value for create and to the existing value on edit).

    2) Yes, use the focus option of the form-options object to either disable the initial focus, or have a different field gain focus when opening.

    Regards,
    Allan

  • piq_pm_pjkpiq_pm_pjk Posts: 21Questions: 7Answers: 1
    Answer ✓

    in regards to part 2)

    I added the form-option: focus to my JS file, but no luck:

    $('#shipments').on( 'click', 'tbody tr', function () {
        editor.edit( this, {
            focus: 1    
        } );
    } );
    

    I just thought, i was opening editor form with a create, so maybe that is why.

    but,

    I had already tried this:

    editor.on( 'onOpen', function() {
        $('input', editor.node('shipments.ship_quantity')).focus();
    } ) ;
    

    which does put the focus on the ship_quantity input field, but still the calendar opens. So, i instead put a hidden field ( i was already using a hidden field ) at the top of the form. That did the trick.

This discussion has been closed.