table-editor validate input on new or updated row


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

Odhran pro premium priority asked 3 years 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 (e.row.name === "") { showErrorMessage("All fields are required"); e.preventDefault(); } else { addItem(e.row); } });


Dawid Wajszczuk staff commented 3 years 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 https://mdbootstrap.com/docs/standard/plugins/table-editor/#docsTabsAPI under events section.


Odhran pro premium priority commented 3 years 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 3 years ago

Hi,

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,
Dawid


Odhran pro premium priority commented 3 years ago

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


Dawid Wajszczuk staff commented 3 years ago

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


FWUser pro premium priority commented 3 years ago

@Dawid Wajszczuk any news about this feature? I will need it in a couple of weeks and for what I'm reading here, this will be a headache.


Dawid Wajszczuk staff commented 3 years ago

We will try to add this feature ASAP.


FWUser pro premium priority commented 3 years ago

@Dawid Wajszczuk is good to know you guys will work on it. Just to share you an example of our requirement, we will need fields (checkboxes in this case) to be required or not, based on values of another fields. Some of these fields are outside the editable table itself. Would be nice if you just add a required property in the column definition expecting a Boolean, so I can code an inline if statement for the expected value.


Dawid Wajszczuk staff commented 3 years ago

@FWUser Thanks for your feedback. We will take this into consideration.


Please insert min. 20 characters.

FREE CONSULTATION

Hire our experts to build a dedicated project. We'll analyze your business requirements, for free.

Status

Answered

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