Dependent ajax is firing everytime a field opens for editing.

Dependent ajax is firing everytime a field opens for editing.

mridulap2003mridulap2003 Posts: 2Questions: 1Answers: 0

I am using the dependent() api with editor for inline editing. It works great. There is just the one issue where the ajax is fired everytime the inline editor opens when I click on any field in the table.

Here is some code:

`

editor.dependent('constituent_country_code', function(val, data, callback) {
    $.NpoPlazaAjax({
        url: buildUrl(stateOptionsPath, {
            ':country_code': val
        }),
        type: 'get',
        dataType: 'json',
        success: function ( json ) {
        callback({ values: {}, options: { 'constituent_state_code': json.map(function(i) { return { label: i.name, value: i.code } }) } }  );
        }
   })
})

`

I would like for it to fire only when the value of 'constituent_country_code' changes. How can I fix this?

Answers

  • allanallan Posts: 51,422Questions: 1Answers: 7,754 Site admin

    The problem there is that the value does actually change when you trigger the editing. Its setting the value to match the row that is being edited. So having that Ajax request to keep things in sync is probably a good thing!

    Allan

  • peterbrownepeterbrowne Posts: 103Questions: 23Answers: 0

    Yes, but how to make it refesh the ajax content ONLY when the dependant parent select is changed?

  • allanallan Posts: 51,422Questions: 1Answers: 7,754 Site admin

    I'm afraid I don't understand - it is only called when the parent select is changed (either by the initialisation of an edit or create action) or the end user changes it. As I noted above, the initialisation must trigger the change event to keep things in sync.

    Perhaps its too early in the morning for me, but could you clarify your question please? :smile:

    Allan

Sign In or Register to comment.