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

[Bug]: input field validation doesnt work #437

Open
3 tasks done
lschwend opened this issue Nov 24, 2023 · 9 comments · May be fixed by #438
Open
3 tasks done

[Bug]: input field validation doesnt work #437

lschwend opened this issue Nov 24, 2023 · 9 comments · May be fixed by #438
Labels
bug Something isn't working

Comments

@lschwend
Copy link

Before submitting...

Context

IIn Materialize 1.0.0, input field validation occurred automatically by adding the attributes data-error and data-success. Additionally, enabling regex validation for input fields would enhance functionality.

Current Behavior

The data-error does nothing when you write an invalid e-mail for example.

Codepen: https://codepen.io/lschwend98/pen/wvNXvbz

Expected behavior

Validate the type and add the error or success mesage to the input field.

Possible Solutions or Causes

Maybe the functionality was removed and could be added again?

Steps to reproduce

No response

Your Environment

  • Version used: 2.0.3 beta
  • Browser Name and version: Google Chrome Version 119.0.6045.160
  • Operating System and version (desktop or mobile): desktop
  • Additional information you want to tell us:
@lschwend lschwend added the bug Something isn't working label Nov 24, 2023
Jerit3787 added a commit to Jerit3787/materialize that referenced this issue Nov 29, 2023
Jerit3787 added a commit to Jerit3787/materialize that referenced this issue Nov 29, 2023
Jerit3787 added a commit to Jerit3787/materialize that referenced this issue Nov 29, 2023
@Jerit3787 Jerit3787 linked a pull request Nov 29, 2023 that will close this issue
8 tasks
@Jerit3787
Copy link

Hi, yeah thanks for reporting it. I have created a PR for this fix. Apparently, many functions were removed due to jQuery. I'm sure this might affecting other components as well. While you're here, please do test it out and check other types of input as well. Thanks :)

Jerit3787 added a commit to Jerit3787/materialize that referenced this issue Nov 29, 2023
@Jerit3787 Jerit3787 self-assigned this Nov 29, 2023
@lschwend
Copy link
Author

lschwend commented Dec 4, 2023

Hi, yeah thanks for reporting it. I have created a PR for this fix. Apparently, many functions were removed due to jQuery. I'm sure this might affecting other components as well. While you're here, please do test it out and check other types of input as well. Thanks :)

Thank you for your PR, looks good. How can I test, if it also works with type="date" or type="number" for Example? Also would be great if it works with required attribute?

@Jerit3787
Copy link

Hi, yeah thanks for reporting it. I have created a PR for this fix. Apparently, many functions were removed due to jQuery. I'm sure this might affecting other components as well. While you're here, please do test it out and check other types of input as well. Thanks :)

Thank you for your PR, looks good. How can I test, if it also works with type="date" or type="number" for Example? Also would be great if it works with required attribute?

https://github.com/materializecss/materialize/suites/18597325789/artifacts/1080727369 you can replace the files with these. Not sure, I might need to check deeper if any old features were removed.

@Jerit3787 Jerit3787 removed their assignment Dec 5, 2023
@Jerit3787
Copy link

I dropped myself from fixing this issue. Sorry, I don't currently have time to complete this.

@gselderslaghs
Copy link

@Jerit3787 could you provide me a brief description on what still needs to be done to address this issue?

@gselderslaghs
Copy link

*Update: As I looked a bit deeper into this issue, as there is HTML5 validation introduced in 2013, this seem to work properly on submit in combination with the Materialize library, the above CodePen example is apparently missing the submit button. In case of form input without a submit button, with AJAX for example, check out the Javascript validation API:

CodePen example

@Jerit3787
Copy link

@Jerit3787 could you provide me a brief description on what still needs to be done to address this issue?

Yeah, so far there materialize doesn't check for any validation methods, namely email and others. In my PR, I've reimplemented the validation feature that was removed before this. You can take a look at it for any reference

@Jerit3787
Copy link

Jerit3787 commented Oct 16, 2024

*Update: As I looked a bit deeper into this issue, as there is HTML5 validation introduced in 2013, this seem to work properly on submit in combination with the Materialize library, the above CodePen example is apparently missing the submit button. In case of form input without a submit button, with AJAX for example, check out the Javascript validation API:

CodePen example

Yeah the HTML5 validation still works, but there is no feedback in terms of the Text Input component like a red bar showing error / customized error message. In previous implementation, materialize will check once user leaves focus (i think?) or press enter on keyboard and instantly shows a red if the validation found an error on the user inputs.

gselderslaghs added a commit to gselderslaghs/materialize that referenced this issue Oct 31, 2024
gselderslaghs added a commit to gselderslaghs/materialize that referenced this issue Oct 31, 2024
@gselderslaghs
Copy link

I've reviewed PR #438, which works as expected, except that the styling for handling invalidity of the field was still missing

Regarding my previous notation on HTML5 validation: there is a possibility to extend existing Materialize styling to the invalid CSS pseudo selector, however implementing an email type input which has attribute required makes it a bit more complex as expected, as mentioned in this comment by Jerit3787. The field is marked as invalid immediately since there is no value, not sure if there is any workaround for this, need to dig a bit deeper into the HTML5 validation on a required (empty) field

A new PR (#521) with enhancements and additions has been created

@Jerit3787 I've refactored the code slightly and removed valid class from a point of view where input should always be considered valid as default except if a invalid error status is thrown

Missing CSS classes and styling for handling the invalidity of the field have been added

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants