Skip to content

Commit a9a9c69

Browse files
authored
Merge pull request #2 from kaliber5/docs
Add basic documentation
2 parents 7d9c182 + 17e6f3d commit a9a9c69

File tree

2 files changed

+29
-2
lines changed

2 files changed

+29
-2
lines changed

README.md

Lines changed: 29 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,18 @@
11
ember-bootstrap-constraint-validations
22
==============================================================================
3+
[![CI](https://github.com/kaliber5/ember-bootstrap-constraint-validations/actions/workflows/ci.yml/badge.svg)](https://github.com/kaliber5/ember-bootstrap-constraint-validations/actions/workflows/ci.yml)
34

4-
[Short description of the addon.]
5+
This addon integration with [ember-bootstrap](https://www.ember-bootstrap.com/) to support form validations based on the
6+
browser's native HTML5 [constraint validation API](https://developer.mozilla.org/en-US/docs/Web/Guide/HTML/Constraint_validation).
7+
But instead of the browser's built-in validation UI, validation errors will be rendered using Bootstrap's [Custom Styles](https://getbootstrap.com/docs/5.2/forms/validation/#custom-styles).
8+
See the [FormElement documentation](https://www.ember-bootstrap.com/api/classes/Components.FormElement.html) for
9+
further details.
510

611

712
Compatibility
813
------------------------------------------------------------------------------
914

15+
* Ember Bootstrap v5 or above
1016
* Ember.js v3.24 or above
1117
* Ember CLI v3.24 or above
1218
* Node.js v12 or above
@@ -23,7 +29,28 @@ ember install ember-bootstrap-constraint-validations
2329
Usage
2430
------------------------------------------------------------------------------
2531

26-
[Longer description of how to use the addon in apps.]
32+
Apply the HTML5 validation attributes as needed to your form controls. The form elements [`@controlType`](https://www.ember-bootstrap.com/api/classes/Components.FormElement.html#property_controlType)
33+
argument will already apply the correct `type` attribute for the rendered `<input>` element. But you can also add
34+
additional HTML5 attributes like `required`, by applying them as attributes to the form control.
35+
For this you must use the block form syntax of form elements, so you can apply them to the yielded form `control` (which basically represents the `<input>`),
36+
and not the parent *element* (a wrapper `<div>`):
37+
38+
```hbs
39+
<BsForm @model={{this.model}} as |form|>
40+
<form.element @label="Name" @property="name" as |el|>
41+
<el.control required minlength="3"/>
42+
</form.element>
43+
<form.element @controlType="email" @label="Email" @property="email" />
44+
<form.submitButton>Submit</form.submitButton>
45+
</BsForm>
46+
```
47+
48+
In this example we have defined a "Name" text field, which is `required` and has a `minlength` of 3, as well as an optional field of type
49+
`email`. When submitting this form, or when focussing out of a field, the appropriate Bootstrap validation markup will be rendered:
50+
51+
![validated form](./docs/validated-form.png)
52+
53+
Note that the error messages are natively provided by the browser itself, given by the form element's [`validationMessage`](https://developer.mozilla.org/en-US/docs/Web/API/Constraint_validation#validationmessage).
2754

2855

2956
Contributing

docs/validated-form.png

54 KB
Loading

0 commit comments

Comments
 (0)