Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Invalid item can still be saved #2

Open
enzolupia opened this issue Feb 24, 2022 · 4 comments
Open

Invalid item can still be saved #2

enzolupia opened this issue Feb 24, 2022 · 4 comments

Comments

@enzolupia
Copy link

Expected Behavior

Invalid fields prevent item from being saved.

Current Behavior

Invalid field still allow item to be saved .

Screen.Recording.2022-02-24.at.15.17.35.mov

Apparently, if the field is marked as valid at least once, directus will allows to save the item even if it not valid anymore.

Steps to Reproduce

  1. Create a masked field with email template.
  2. Create a new field and input a valid email address, example test@email.com.
  3. Notice that directus allow the item to be saved.
  4. Delete last 3 chars so that email is equals to test@email (<- invalid).
  5. Directus still allow the item to be saved.
@dimitrov-adrian
Copy link
Owner

dimitrov-adrian commented Feb 26, 2022

The problem to close this one is that there is no way to prevent save action. Directus actually enables the save button if any value is changed, so every interface need to emit new value as soon as the value is changed.

I am thinking of two approaches to deal with that

  1. Fixing the Email not validated when deleting #1 so no emit action until value is successful
  2. Prevent typing anything not allowed. This actually will be very tricky, especially if using custom pattern like regex.

@enzolupia
Copy link
Author

I agree that option 1 may be the only solution. It should handle all possible way to delete the content of the input, i.e.:

  1. Delete using backspace
  2. Select all (cmd+A) and delete
  3. Select all and cut (cmd+a + cmd+x)
  4. Select all and cut/delete from right click menu

Probably firing validation on keystroke (like I suppose it is working now) it's not the best way to handle this scenarios, maybe a listener on value change is a better option.

@dimitrov-adrian
Copy link
Owner

I think the points are covered now. I also added a reset initial value on blur when invalid.

Just preventing saving is not possible with current Directus and the interface itself.

I am thinking of another approach because in the 9.8 there is validation setup, which validation rules also support regex patterns, so rules could be parsed and used instead.

@SalahAdDin
Copy link

@enzolupia did you checked it?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants