-
Notifications
You must be signed in to change notification settings - Fork 444
feat(gnoweb): support required attribute for markdown form fields #4974
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
base: master
Are you sure you want to change the base?
Conversation
🛠 PR Checks SummaryAll Automated Checks passed. ✅ Manual Checks (for Reviewers):
Read More🤖 This bot helps streamline PR reviews by verifying automated checks and providing guidance for contributors and reviewers. ✅ Automated Checks (for Contributors):🟢 Maintainers must be able to edit this pull request (more info) ☑️ Contributor Actions:
☑️ Reviewer Actions:
📚 Resources:Debug
|
Codecov Report❌ Patch coverage is
📢 Thoughts on this report? Let us know! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The required flag only controls whether the required attr is added or not, and all other user unputs are properly handled with HTMLEscapeString, so there doesn't appear to be any injection threat in this PR. LGTM
EDIT: Some CIs are failing now. could you check this if possible? thank you
|
Maybe required form fields could be parsed to render with the required attribute, that way forms would get basic default browser validation on submit click, if it makes sense |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The feature looks useful! However I have a few points before merging:
- I assume we're fully relying on browser's native HTML5 validation (blocks submission + shows default tooltip). This approach supports front-end minimalism which is what we want, and I don't see any JS changes so just confirming thats the intended scope? @jeronimoalbi it already does that what should block the onSubmit JS event.
- I noticed there's no new tests included in the PR. Since this modifies the markdown parser logic in
ext_forms.go, could you add a test case (eg a.txtargoldenfile) to verify that the required attribute is correctly rendered in the HTML output for all the field types the form can generate (input, textarea, select, radio, checkboxes etc)? - Would be great to add a concrete example in r/demo/markdown or similar to demonstrate the syntax and verify it works as expected live across browsers (for input, textarea, select, radio, checkboxes etc).
- Native validation handles the blocking but browser styling for invalid fields varies alot (Chrome doesn't outline in red by default for ex). Did you consider adding CSS rules like the
:invalid pseudo-class(maybe combined with :focusor:user-invalid) to style the input border in red when a required field is empty after user interaction? This would make the error state more consistant across browsers and improve UX. - Currently only an asterisk * is displayed. While common, it may not be clear to every user what it means. Could you add a small explicit text like "required" or "(required)" after the field label, or at least a legend at the top of forms explaining what * means?
Thanks!
45f8c3b, is it more explicit? preview:
|
|
|
Hey! These latest commits add CSS styling for native form validation (red border when a required field is invalid after user interaction). I also fixed the (required) badge display logic: spaces and for radios it shows in the description above the group (since validation applies to the whole group), while for checkboxes it shows next to each individual checkbox (since in native HTML, each required checkbox must be checked separately). I want to test this locally before merging to make sure the behavior works correctly across different browsers. |


Description
Closes #4970
This PR adds support for the required="true" attribute in Gno-flavored markdown form fields.
Usage
required="true"can be added to:<gno-input>,<gno-textarea>,<gno-select>Preview