1: 2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15: 16: 17: 18: 19: 20: 21: 22: 23: 24: 25: 26: 27: 28: 29: 30: 31: 32: 33: 34: 35: 36: 37: 38: 39: 40: 41: 42: 43: 44: 45: 46: 47: 48: 49: 50: 51:
<?php
class FormFieldConstraintNotEmpty extends AbstractFormFieldConstraint
{
private $error_message;
public function __construct($error_message = '')
{
if (empty($error_message))
{
$error_message = LangLoader::get_message('form.has_to_be_filled', 'status-messages-common');
}
$this->error_message = $error_message;
}
public function validate(FormField $field)
{
$value = $field->get_value();
$this->set_validation_error_message(StringVars::replace_vars($this->error_message, array('name' => TextHelper::strtolower($field->get_label()))));
if ($value instanceof FormFieldEnumOption) {
return $value->get_raw_value() !== null && $value->get_raw_value() != '';
}
if ($value instanceof Date) {
return $value->format(Date::FORMAT_ISO_DAY_MONTH_YEAR) !== null && $value->format(Date::FORMAT_ISO_DAY_MONTH_YEAR) != '';
}
return $value == 0 || ($value !== null && $value != '');
}
public function get_js_validation(FormField $field)
{
return 'notEmptyFormFieldValidator(' . TextHelper::to_js_string($field->get_id()) .
', ' . TextHelper::to_js_string(StringVars::replace_vars($this->error_message, array('name' => TextHelper::strtolower($field->get_label())))) .')';
}
}
?>