Getting current field data in preBlur

Getting current field data in preBlur

anthonysanthonys Posts: 19Questions: 4Answers: 0

I have an item in a multiselect that I only want the user to be able to choose in one row at a time. When the user selects this item in a row I want it to be unset in all other rows. I would like the unsetting event to be submitted to the server as part of the edit that sets the item as per the user's original set request. I am using inline editing.

I am trying to get the value of an inline edit before it is submitted and am using the preBlur event to do so. The only event in preBlur is however 'e', which I can't see a way of using. I also have 'this' which corresponds to an editor instance, but when i do this.get() I get the current data for all fields, and I'm not sure which field the user is even editing.

My plan, once I get the value of the field that is being submitted, is to find any other instances of the item in the table and unset them using another editor.set() call.

Any ideas on how to achieve this would be appreciated.

Answers

  • allanallan Posts: 61,663Questions: 1Answers: 10,095 Site admin

    Hi,

    The size attribute of the select element can be used limit the selection to just a single item: http://live.datatables.net/xabofufo/1/edit (note you need to set the height of the select element as well, otherwise it reduces to 1 option).

    You can set attributes of the select element using the attr option of the select field type.

    Regards,
    Allan

  • anthonysanthonys Posts: 19Questions: 4Answers: 0

    Hi Allan

    Thanks for the response. I think your suggestion would limit selection within a multiselect to one option. I am trying, when an item is selected in one row to remove it from another row in the same datatable.

    Best regards

    Anthony

  • allanallan Posts: 61,663Questions: 1Answers: 10,095 Site admin

    Oh I see what you mean - thanks for the clarification.

    What you would probably need to do is listen for the postEdit event and check to see if there are any other rows in the table which use the selected value. If they do, then trigger another Editor edit() which would remove that value.

    You have to wait until submitComplete until you can start a new edit - e.g.:

    editor.on( 'postEdit', function ( ... ) {
       ... logic
    
      if ( needToUpdate ) {
        editor.one( 'submitComplete', function () {
          ... edit and submit
        }
      }
    } );
    

    Allan

This discussion has been closed.