Is there a way to prevent duplicate entry in editor with 2 fields ?

Is there a way to prevent duplicate entry in editor with 2 fields ?

Mairie du PecqMairie du Pecq Posts: 9Questions: 3Answers: 0

Hi,

I am seeking if it's possible to add control when a user add duplicate values.

I use Datatables and Editor and when i add a new entrie with the firstname, lastname and other stuffs, i would like to check if the firstname and lastname already exist before insert or update the database.

I thinck i need to use "postCreate" and "postEdit" but could you please confirm it to me.

This question has an accepted answers - jump to answer

Answers

  • allanallan Posts: 61,723Questions: 1Answers: 10,108 Site admin
    Answer ✓

    A validator would be the way to do this. If you were checking with just a single column you could use the pre-build unique validator, but since you have two fields, you'd need to query the database manually to check if there is already matching data.

    A few notes about this:

    1. Use a global validator and perform this check only on the create action
    2. What if you have two "John Smith"s in the database? Perhaps it needs a check on another field as well?
    3. If first name and last name must be unique, put a unique restriction on those columns in the database. Then worst case is they get an SQL error even if you don't add a custom validator.
    4. Editor doesn't have the option to convert a create action into an edit. You'd need to have the validator return an error and the user would then have to edit their entry, cancelling the create action.

    Allan

Sign In or Register to comment.