# @soleil-se/config-validate

Simple config validation.\
Validate configuration with the built in validation in the browser, for most common use cases such as required, simple formatting (mail, url tel) and so on.

## Installation

```sh
npm i @soleil-se/config-validate
```

## Usage

In `./config/config.js` or `./config_global/config.js` we need to register the validate function on the `window` object.\
<https://developer.sitevision.se/docs/webapps/configuration/config.js#h-Validate>

* 1.3.0

  ```js
  import { registerConfigValidate } from '@soleil-se/config-validate';


  registerConfigValidate();
  ```

* 1.0.0 (Deprecated)

  ```js
  import validate from '@soleil-se/config-validate';


  window.validate = validate;
  ```

All styling that is needed is appended to head. To add a required asterisk after a label add the class `control-label--required`.

```html
<div class="form-group">
  <label class="control-label control-label--required">Text</label>
  <input class="form-control" name="text" required>
</div>
```

> **Caution**
>
> It’s important to only put one input field in each form group!\
> For example this will only validate the last input-field and incorrectly show validation messages.
>
> ```html
> <div class="form-group">
>   <label class="control-label control-label--required">Text</label>
>   <input class="form-control" name="text1" required>
>   <input class="form-control" name="text2" required>
> </div>
> ```