allow and validate needed (required) attribute for file uploads, checkboxes and radio buttons

This commit is contained in:
Ralf Becker 2010-07-21 08:21:42 +00:00
parent 09719babaf
commit 4da973400c

View File

@ -1336,6 +1336,7 @@ class etemplate extends boetemplate
self::$request->set_to_process($form_name,$cell['type'],array(
'unset_value' => $unset_val,
'multiple' => $multiple,
'needed' => $cell['needed'],
));
}
self::$request->set_to_process_attribute($form_name,'values',$set_val,true);
@ -1361,7 +1362,9 @@ class etemplate extends boetemplate
else
{
$html .= html::input($form_name,$set_val,'RADIO',$options);
self::$request->set_to_process($form_name,$cell['type']);
self::$request->set_to_process($form_name,$cell['type'],array(
'needed' => $cell['needed'],
));
}
break;
case 'button':
@ -1636,7 +1639,9 @@ class etemplate extends boetemplate
self::$form_options = " enctype=\"multipart/form-data\" onsubmit=\"set_element2(this,'$path_name','$form_name')\"";
}
$html .= html::input($form_name,'','file',$options);
self::$request->set_to_process($form_name,$cell['type']);
self::$request->set_to_process($form_name,$cell['type'],array(
'needed' => $cell['needed'],
));
}
break;
case 'vbox':
@ -2243,8 +2248,12 @@ class etemplate extends boetemplate
self::set_array($content,$form_name,$value);
break;
case 'checkbox':
if ($value === false) // get_array() returns false for not set
if (!$value)
{
if ($attr['needed'])
{
self::set_validation_error($form_name,lang('Field must not be empty !!!',$value),'');
}
self::set_array($content,$form_name,$attr['multiple'] ? array() : $attr['unset_value']); // need to be reported too
}
else
@ -2296,6 +2305,10 @@ class etemplate extends boetemplate
//echo $form_name; _debug_array($value);
// fall-throught
default:
if ($attr['needed'] && !$value)
{
self::set_validation_error($form_name,lang('Field must not be empty !!!',$value),'');
}
self::set_array($content,$form_name,$value);
break;
}