table-editor validate input on new or updated row

Topic: table-editor validate input on new or updated row

Odhran pro premium priority asked 2 weeks ago

How do validate a new or updated row on the table-editor plugin? I want to add a new row and if the name is blank, prevent any further code being called.

I've tried checking the values manually and calling preventDefault on the event, but it still goes on to call the table editor "update" and "exit" methods of the table-editor which closes the row.

table.addEventListener('add.mdb.tableEditor', e => { if ( === "") { showErrorMessage("All fields are required"); e.preventDefault(); } else { addItem(e.row); } });

Dawid Wajszczuk staff commented a week ago

Hi. First of all, add.mdb.tableEditor event is being fired after adding a new row, so it is too late to stop this. I would try one of these events instead: edit.mdb.tableEditor, exit.mdb.tableEditor, update.mdb.tableEditor. More information about the events can be found here under events section.

Odhran pro premium priority commented a week ago

I don't think that's correct.

edit is fired when I click the + button. The new row is displayed at this point with empty values waiting for me to fill it in. add is fired when I click the save action button. then update, and then exit.
So add is the first event fired where I can check the values.

where can I stop the event from proceeding?

Dawid Wajszczuk staff answered a week ago


I have checked the source code and currently it is not possible to prevent events from further proceeding. But I have added this to our list.

Keep coding,

Odhran pro premium priority commented 4 days ago

So there's no way to validate input?
Any workaround for this?

Dawid Wajszczuk staff commented 4 days ago

Currently there is no way to validate these inputs and there is no workaround :/

Please insert min. 20 characters.


Specification of the issue
  • User: Pro
  • Premium support: Yes
  • Technology: MDB Standard
  • MDB Version: MDB5 3.10.0
  • Device: laptop
  • Browser: Chrome
  • OS: Windows
  • Provided sample code: No
  • Provided link: No