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: 61,446Questions: 1Answers: 10,054 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: 314Questions: 54Answers: 0

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

  • allanallan Posts: 61,446Questions: 1Answers: 10,054 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

  • Scott BowersScott Bowers Posts: 13Questions: 2Answers: 0

    I know this is an old question but I am running into the same thing, on in input field as well as selects. Just clicking in a field, even an input field it dependent function fires, but the value of the field hasn't actually changed. Is there a way to change the dependent function to only fire when the user tabs out of the field? Or to check if the value changed?

  • allanallan Posts: 61,446Questions: 1Answers: 10,054 Site admin

    Hi Scott,

    I've added a reply to your similar question here.

    Allan

This discussion has been closed.