Jump to content

Run Event Listener on Tabular Report 'Edit' Button/Link


Recommended Posts

I'm trying to disable some fields when the user is attempting to Inline Edit a record on my tabular report.

I want to keep these fields 'editable' in the wizard so that the user can submit new records with the Inline Add button.

I had a script running off of the InlineEdit button onclick that would disable the fields. This worked, but only for the top record in the report and only the first time you click it. 

So, I've tried this, with no luck either:

var elements = document.querySelectorAll("a[data-cb-name='InlineEdit']");
for(var i = 0, len = elements.length; i < len; i++) {
  elements[i].onclick = function () {
    setTimeout(function(){
      document.querySelector('select[id*="InlineEditEmployee_"]').disabled = true;
      document.querySelector('select[id*="InlineEditEquipment_"]').disabled = true;
      document.querySelector('select[id*="InlineEditBrand_"]').disabled = true;
      document.querySelector('input[id*="InlineEditSerial_"]').disabled = true;
      document.querySelector('input[id*="InlineEditInspection_Date_"]').disabled = true;
      document.querySelector('select[id*="InlineEditFP_Inspector_"]').disabled = true;
    }, 3000);
  }
}

Any help would be appreciated.

Link to comment
Share on other sites

  • 2 months later...

Hi there!

I believe mutationobserver might be useful.

Here is how this solution might look:
 

let observer = new MutationObserver( mutationRecords => {
if(document.querySelector('select[id*="InlineEditEmployee_"]')!==null) {
      document.querySelector('select[id*="InlineEditEmployee_"]').disabled = true;
      document.querySelector('select[id*="InlineEditEquipment_"]').disabled = true;
      document.querySelector('select[id*="InlineEditBrand_"]').disabled = true;
      document.querySelector('input[id*="InlineEditSerial_"]').disabled = true;
      document.querySelector('input[id*="InlineEditInspection_Date_"]').disabled = true;
      document.querySelector('select[id*="InlineEditFP_Inspector_"]').disabled = true;
}
});
observer.observe(document.querySelector('article'), {childList: true, subtree: true});


I tested it on my table with different fields and it worked fine.

Let me know if you have any questions about this approach.

Link to comment
Share on other sites

  • 5 months later...

Hello!

I've tried this code (with the MutationObserver) but there are 2 issues:

Update doesn't work anymore, I get an error on the disabled fields saying "Cannot update this record because there are related records in the database". I believe the fields value are not send to be saved.

It doesn't work on mobile version. The field is changing it's appearance (like is disabled) but you still can change the selected value.

Maybe there is another solution to this ?

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...