@KK - Putting the validators to use on other websites, great stuff!
Ran into small issue, could use some help.
The function raises a text error, which returns in with all the other errors. This website does not use text errors and just adds a class to the field to change it's appearance and I accomplish this with something like:
- Code: Select all
class="field-box<cms:if k_error_other_reason> error</cms:if>"
I did try that, with no luck so assumed it was just not being set, so I tried to add to the function:
- Code: Select all
$CTX->set('k_error_other_reason', '1', 'global');
prior to the return of raise_error.
- Code: Select all
// Custom validator for form field (blutbaden)
function req_on_submit( $field, $args ){
global $CTX;
$CTX->set('k_error_other_reason', '', 'global'); // clear previous error sets
// check if 'other' option selected..
$val = trim( $field->get_data() );
if( $val=='Other' ){
// check that the 'other_reason' textbox is not left empty then ..
$f = $field->page->_fields['other_reason'];
if( !is_null($f) ){
$val = trim( $f->get_data() );
if( !strlen($val) ){
$CTX->set('k_error_other_reason', '1', 'global');
return KFuncs::raise_error( "'Other reason' cannot be left empty" );
}
}
}
}
When I add:
- Code: Select all
<cms:if k_error_other_reason> error</cms:if>
To the html anywhere, I get error displayed and it seems to function.
When I add it to the bound:
- Code: Select all
<cms:input type="bound" name="other_reason" class="field-box<cms:if k_error_other_reason> error</cms:if>" id="other_reason" />
Here is the editable for the other_reason:
- Code: Select all
<cms:editable name='other_reason' label='Other reason' type='text' />
It does not add the error class. This was my attempt to try to get it working, am I on the right path?