Redirects mechanism should read its configuration form <knotx:router> tags.
User will be redirected to the page that is pointed by the first <knotx:router> tag spotted on page after Handlebars processing.
The priority of redirects is defined inside <knotx:router> tag - from the most important to the least.
In following example:
<script data-api-type="templating"
type="text/x-handlebars-template"
data-uri-post-formA="/service/mock/step1.json"
data-uri-all-labelsRepository="/service/mock/labelsRepository.json"
data-id="step1">
<knotx:router>
{
_default._response.statusCode: {
"5*": "/error" //when any _response (formA or labelsRepository in this case) status code would be 5XX, Knot.x will redirect user to '/error' page
},
formA.success: {
true: "/step2" //when formA responses with `success: true`, Knot.x will redirect user to `/step2` page
//false: validation failed - we stay where we are
}
}
</knotx:router>
<div id="login-form-wrapper">
<h1>{{labelsRepository.loginHello}}</h1>
{{#if formA && !formA.success}}
<p>{{labelsRepository.validationError}}</p>
{{/if}}
<form method="post" class="form-inline" id="formA">
<div class="form-group">
<label for="email">Email</label>
<input type="email" name="email" id="email" value="{{_request.email}}"/>
<label for="birthDate">Date of birth</label>
<input type="text" name="birthDate" id="birthDate" value="{{_request.birthDate}}"/>
</div>
<button type="submit" class="btn btn-default">Submit</button>
<input type="hidden" name="_id" value="step1"/>
</form>
</div>
</script>
If formA service response with success: true but labelsRepository response status Code would be 503 user should be redirected to /error page.
Provide an example usage of this mechanics in knotx-example, e.g. 2-level form:
step1: provide your email and date of birth (with snippet presented above)
Redirects mechanism should read its configuration form
<knotx:router>
tags. User will be redirected to the page that is pointed by the first<knotx:router>
tag spotted on page after Handlebars processing. The priority of redirects is defined inside<knotx:router>
tag - from the most important to the least. In following example:If
formA
service response withsuccess: true
butlabelsRepository
response status Code would be503
user should be redirected to/error
page.Provide an example usage of this mechanics in
knotx-example
, e.g. 2-level form: