material-components / material-components/material-web

error handling readOnly input's validity object and validationMessage

Open
#5,750 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
SCSS
Stars
11.3k
Forks
1.1k
Avg merge
20h 28m
Merged PRs (30d)
13

Description

### What is affected?

Component

### Description

``

Default step value for this is "1". Now if you set this **readOnly** input in JS document.getElementById("123").value = "0.5" you'll get following:
```
input.reportValidity() = true
input.checkValidity() = true
```
BUT
input.validity Object will have "stepMismatch: true"
and
input.validationMessage = ''.
This seems to be a problem for material-web internal validation logic. It doesn't like a property of the validity object to be 'true' and an empty validationMessage at the same time.

### Reproduction

create a number readOnly material web input and set its value to "0.5"

### Workaround

Ensure all the inputs would be theoretically valid, although validation shouldn't be triggered in this case.

### Is this a regression?

No or unsure. This never worked, or I haven't tried before.

### Affected versions

1.5.0

### Browser/OS/Node environment

Chrome, Windows

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

No source file or test is named. Start by reproducing the readOnly number input case in Chrome with value "0.5", then trace the material web input's validation handling and compare reportValidity(), checkValidity(), validity.stepMismatch, and validationMessage. Done means the component handles this combination consistently without breaking expected validation behavior.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript
Domain
frontend, web-dev
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.