Skip to content

Commit

Permalink
improve validation section for NumberField
Browse files Browse the repository at this point in the history
  • Loading branch information
vursen committed Oct 2, 2024
1 parent 8463056 commit dcf9da1
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 4 deletions.
2 changes: 1 addition & 1 deletion articles/components/date-picker/index.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -92,8 +92,8 @@ endif::[]
--

It's important to ensure an appropriate error message is configured for each constraint violation to provide users with clear feedback.

ifdef::flow,lit[]

=== Custom Validation

For more complex cases where constraint validation isn't enough, Flow and Hilla offer the Binder API that allows you to define custom validation rules. This is useful, for example, when you want to limit the options to Monday through Friday. In the following example, try selecting a date that's on a Sunday or a Saturday to see a custom validation message.
Expand Down
31 changes: 28 additions & 3 deletions articles/components/number-field/index.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -74,11 +74,31 @@ include::{root}/frontend/demo/component/numberfield/react/number-field-step-butt
endif::[]
--

== Minimum and Maximum Value
[.collapsible-list]
== Validation

The valid input range of a Number Field is set by defining the minimum and maximum values.
Number Field provides a validation mechanism based on constraints. Constraints allow you to define criteria that the value must meet to be considered valid. Validation typically occurs when the user initiates a value change, for example by entering input and pressing kbd:[Enter]. If the value is invalid, the field is visually highlighted in red, and an error message appears underneath the input.

You can set the helper text to give information about the range.
Below is a list of supported constraints with more detailed information:

[.example]

include::{articles}/components/_input-field-common-features.adoc[tags=bad-input;required]

[#min-and-max-value]
.Min & Max Value
[%collapsible]
====
The valid input range of a Number Field can be restricted by defining `min` and `max` values. Helper text can be used to inform the user about the accepted range.
====

.Step
[%collapsible]
====
Refer to the <<#step,Step>> section for more details and an example.
====

The following example demonstrates how to create a quantity field using a combination of these constraints:

[.example]
--
Expand All @@ -105,6 +125,11 @@ include::{root}/frontend/demo/component/numberfield/react/number-field-validatio
endif::[]
--

It's important to ensure an appropriate error message is configured for each constraint violation to provide users with clear feedback.

include::{articles}/components/_input-field-common-features.adoc[tags=binder]


== Step

The step value of a Number Field defines the numeric intervals that are allowed.
Expand Down
1 change: 1 addition & 0 deletions articles/components/text-field/index.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@ It's important to ensure an appropriate error message is configured for each con

include::{articles}/components/_input-field-common-features.adoc[tags=binder]


// Readonly and disabled

include::{articles}/components/_input-field-common-features.adoc[tag=readonly-and-disabled]
Expand Down

0 comments on commit dcf9da1

Please sign in to comment.