0.7.0 • Published 12 years ago
chained v0.7.0
Chained Browser Demo
This demo shows a form validation DSL implemented with Chained in Coffeescript:
form '#form', ( check ) ->
field '#fname', (f) ->
check(f.value).isNotNull().isLengthAtLeast(of: 2).show(f)
field '#lname', (f) ->
check(f.value).isNotNull().isLengthAtLeast(of: 2).show(f)
field '#uname', (f) -> check(f.value).isNotNull().userNameShouldNotExist(msg: 'User already exists').show(f)
field '#password1', (f) ->
check(f.value).isNotNull().isLengthAtLeast(of: 4).show(f)
field '#password2', (f) ->
check(f.value).isNotNull().shouldMatchElement(element: '#password1', msg: "passwords should match").show(f)formandfieldfunctions setupfocusoutcallbacks with chained, deferred objects.checkis an alias forchained._.The method
showrenders popup error messages whenever one of the promise associated with a predicate-chain fails.The method
userNameShouldNotExistis based on an Ajaxgetand, as such, is promise based. Chained allows to use the result in the next predicate as if it were synchronous. The users file at the moment contains only the userzack.