@@ -24,7 +24,7 @@ Features:
2424- Support for 'pure render' optimization.
2525- Reference implementation of 'linked' UI controls (` tags.jsx ` ).
2626 - Standard tags: ` <Input /> ` and ` <TextArea /> ` (with validation), ` <Select /> ` ,
27- - Custom tags: ` <Radio /> ` , ` <Checkbox /> `
27+ - Custom tags: ` <Radio /> ` , ` <Checkbox /> ` , ` <NumberInput /> `
2828- TypeScript source and type definitions.
2929- Backward compatible with standard React 0.14 links API
3030
@@ -50,6 +50,8 @@ Features:
5050 - ` link.clone() ` creates shallow copy of the enclosed object.
5151- Added "Users List" application example.
5252- ` link.toggle ` is _ removed_ . Use ` link.update( x => !x ) ` instead.
53+ - ` <NumberInput/> ` tag with input rejection for numbers.
54+ - Validator functions for ` link.check ` may contain default ` error ` message.
5355
5456# Installation
5557
@@ -293,6 +295,14 @@ but returns `undefined` and leads to the proper purely functional update of the
293295
294296Evaluate given condition for the current link value, and assign
295297given error object to the ` link.error ` when it fails. There are no restriction on the error object shape and type.
298+
299+ It's possible to assign default error message to the validator function. ` tags.jsx ` provides ` isRequired ` and ` isEmail `
300+ generic validator functions as an examples. Excerpt from ` tags.jsx ` :
301+
302+ ``` jsx
303+ export const isRequired = x => x != null && x !== ' ' ;
304+ isRequired .error = ' Required' ;
305+ ```
296306
297307Checks can be chained. In this case, the first check which fails will leave its error in the link.
298308
@@ -323,14 +333,120 @@ const numLink = List.state( this, 'num' )
323333console .log ( numLink .error );
324334```
325335
326- # Data binding examples
336+ ## Data binding examples
327337
328338Here are the set of [ working] ( https://volicon.github.io/valuelink/databinding.html ) [ examples] ( /databinding.html ) for typical data binding use cases.
329339
330340Also, there's [ working] ( https://volicon.github.io/valuelink ) [ example] ( /example/userslist.jsx ) of an application managing the users list.
331341
332342[ Custom elements boilerplate] ( /tags.jsx ) which is used by both examples is another good example.
333343
344+ ### Text and number form fields
345+
346+ ##### <Input type =" text " />, <TextArea />
347+
348+ ` tags.jsx ` contains wrappers for standard ` <input> ` and ` <textarea> ` tags,
349+ which can be directly bound to the string state elements.
350+
351+ These wrappers will add ` invalid ` class to enclosed HTML element, if an error is present in the bound link.
352+
353+ ``` jsx
354+ < Input type= " text" valueLink= { link } / >
355+ < TextArea valueLink= { link } / >
356+ ```
357+
358+ ##### <NumberInput />
359+
360+ There's also cross-browser implementation of * numeric input* tag. It has following differences compared to ` <Input> ` :
361+
362+ - Keyboard input which obviously leads to invalid values (e.g. letters) are rejected.
363+ - Value is being always converted to valid number.
364+ - There are ` integer ` and ` positive ` boolean props controlling input rejection. They can be combined.
365+
366+ ` <NumberInput> ` validates its value, and adds ` invalid ` class to enclosed input element if it's not a number.
367+
368+ ``` jsx
369+ < NumberInput valueLink= { link } / >
370+ < NumberInput valueLink= { link } integer= { true }/ >
371+ < NumberInput valueLink= { link } positive= { true }/ >
372+ ```
373+
374+ ### Checkboxes
375+
376+ ##### <Input type =" checkbox " >
377+
378+ Wrapper for the standard ` <input> ` . Directly binds boolean value with ` checkedLink ` property.
379+
380+ ``` jsx
381+ < Input type= " text" checkedLink= { booleanLink } / >
382+ < Input type= " text" checkedLink= { arrayLink .contains ( ' option' ) } / >
383+ ```
384+
385+ ##### <Checkbox >
386+
387+ Internally, it's ` <div> ` element which toggles ` selected ` class on click.
388+ Thus, it can be easily styled.
389+
390+ By default, it has ` checkbox ` CSS class, which can be overridden by passing ` className ` prop.
391+
392+ It passes through anything else, including ` children ` .
393+
394+ ``` jsx
395+ < Checkbox checkedLink= { booleanLink } / >
396+ < Checkbox checkedLink= { arrayLink .contains ( ' option' ) } / >
397+ ```
398+
399+ ### Radio Groups and Select list
400+
401+ ##### <Select >
402+
403+ Wrapper for standard <select />. Regular <option /> tags must be used. All props are passed through.
404+
405+ ``` jsx
406+ < Select valueLink= { linkToSelectedValue }>
407+ < option value= " a" > A < / option>
408+ < option value= " b" > B < / option>
409+ < / Select>
410+ ```
411+
412+ ##### <Input type =" radio " >
413+
414+ Wrapper for the standard ` <input> ` . Directly binds boolean value with ` checkedLink ` property.
415+
416+ Can be directly bound to the state member using ` valueLink ` property.
417+
418+ ``` jsx
419+ < label>
420+ A :
421+ < Input type= " radio" valueLink= { flagLink } value= " a" / >
422+ < / label>
423+ < label>
424+ B :
425+ < Input type= " radio" valueLink= { flagLink } value= " b" / >
426+ < / label>
427+ ```
428+
429+ ##### <Radio >
430+
431+ Internally, it's ` <div> ` element which always sets ` selected ` class on click. Thus,
432+ it can be easily styled.
433+
434+ By default, it has ` radio ` CSS class, which can be overridden by passing ` className ` prop.
435+ It passes through anything else, including ` children ` .
436+
437+ It * must* be used in conjunction with ` link.equals( 'value' ) ` method.
438+
439+ ``` jsx
440+ < label>
441+ A :
442+ < Radio checkedLink= { flagLink .equals ( ' a' ) } / >
443+ < / label>
444+ < label>
445+ B :
446+ < Radio checkedLink= { flagLink .equals ( ' b' ) } / >
447+ < / label>
448+ ```
449+
334450[ method ] : /images/method.png
335451[ static ] : /images/static.png
336452[ var ] : /images/var.png
0 commit comments