4 attributes.data default
Florian Bouillon edited this page 1 month ago

data-default

import

import DefaultAttribute from '@dzeio/form-manager/attributes/DefaultAttribute';

am.register(efaultAttribute);
am.setup();

Examples

data-default will NEVER replace a value if one was already set

if input has type="date || time || week” data-default will be filled with new Date(data-default.value) or new Date()

<input type="date" name="date" data-default />

if data-default startsWith run: the rest will be evaluated and the final value will be set

<input type="date" name="date" data-default="run:var t = 'pouet:D';t" /> <!-- value will be "pouet:D" -->

if data-default is equal to child:{text|value|attribute}:{queryselector} the value will be the {text|value|attribute} of {queryselector}

<select name="select" data-default="child:text:option:not(:selected)">
    <option selected>FormManager !</option>
    <option>pouet :D</option> <!-- value will be "pouet :D" -->
</select>

Explication

Most of the time data-default don't have any interests over value="value" but for specials case it has ones !