18 require_once dirname(__FILE__).
'/../../form_question_rule/form_question_rule.inc';
45 parent::__construct($assetid);
60 '==' =>
'Must select exactly this many options...',
61 '!=' =>
'Must not select this many options...',
62 '>' =>
'Must select more than this many options...',
63 '<' =>
'Must select less than this many options...',
64 '>=' =>
'Must select at least this many options...',
65 '<=' =>
'Must select no more than this many options...',
89 $operator = array_get_index($rule_data,
'operator',
'==');
90 $value = array_get_index($rule_data,
'value',
'');
92 $q_name =
'q'.$q_asset->id;
96 $q_id = $q_name.($q_asset->attr(
'multiple') ?
'[]' :
'');
102 $q_id = $q_name.
'[]';
105 $q_safe_name = str_replace(
':',
'_', $q_name);
117 if ($q_asset instanceof Form_Question_Type_Select) {
118 ?>var select = form.elements[
"<?php echo $q_id ?>"];
119 for(i=0; i<select.options.length; i++) {
120 if (select.options[i].selected) selectCount++;
123 foreach ($q_asset->getOptions() as $key => $option) {
124 ?>
if (document.getElementById(
"<?php echo $q_safe_name.'_'.$key ?>").checked) selectCount++;
130 if (!(selectCount <?php echo $operator ?> <?php echo $value ?>)) {
131 submission_errors[submission_errors.length] =
"<?php
132 if (!strlen($q_asset->attr('cust_required_error'))) {
133 ?>You have selected "+selectCount+
" option"+(selectCount == 1 ?
"" :
"s")+
" at question \"<?php echo addslashes($q_asset->attr('name')) ?>\" - <?php
136 echo ' you must select '.$value;
140 echo ' you must not select this many';
144 echo ' you must select more than '.$value;
148 echo ' you must select at least '.$value;
152 echo ' you must select less than '.$value;
156 echo ' you must select no more than '.$value;
161 echo addslashes($q_asset->attr('cust_required_error'));
166 $contents = ob_get_contents();
189 $operator = array_get_index($rule_data,
'operator',
'==');
190 $value = array_get_index($rule_data,
'value',
'');
192 $valid = eval(
'return \''.count($answer).
'\''.$operator.
'\''.$value.
'\';
');
207 function defaultError(&$q_asset, $rule_data)
209 $operator = array_get_index($rule_data, 'operator', '==
');
210 $value = array_get_index($rule_data, 'value
', '');
211 if ($operator == '>=
' && $value == 1 && strlen($q_asset->attr('cust_required_error
'))) {
212 $error_str = $q_asset->attr('cust_required_error
');
214 $selected_options = count($q_asset->getValue());
215 $error_str = translate('core_form_rule_select_limit_error_
'.$operator, $selected_options, $q_asset->attr('name
'), $value);
219 }//end defaultError()
231 function ruleDescription(&$q_asset, $rule_data)
233 $operator = array_get_index($rule_data, 'operator', '==
');
234 $value = array_get_index($rule_data, 'value
', '');
236 $error_str = translate('core_form_rule_select_limit_desc_
'.$operator, $value, $q_asset->attr('name
'));
240 }//end ruleDescription()