/** * @param ISurveyStep $current_step * @param ISurveyQuestionTemplate $question * @param ISurveyAnswer $answer * @return FormField */ public function build(ISurveyStep $current_step, ISurveyQuestionTemplate $question, ISurveyAnswer $answer) { $value = null; if (!is_null($answer)) { $value = $answer->value(); } $field = new SurveyOrganizationField($question, $value); if ($question->isMandatory()) { $field->setRequired(); } return $field; }
/** * @param ISurveyStep $current_step * @param ISurveyQuestionTemplate $question * @param ISurveyAnswer $answer * @return FormField */ public function build(ISurveyStep $current_step, ISurveyQuestionTemplate $question, ISurveyAnswer $answer) { $field = new SurveyRadioButtonMatrixField($question->name(), $question->label(), $question); if (!is_null($answer)) { $field->setAnswer($answer); } if ($question->isReadOnly()) { $field->setDisabled(true); } if ($question->isMandatory()) { $field->setValidationAttribute('data-rule-radio_button_matrix_required', $field->name); $field->setValidationAttribute('data-msg-radio_button_matrix_required', sprintf('you must select at least one item (%s)', $question->name())); } $this->buildDependantRules($current_step, $question, $field); return $field; }
/** * @param ISurveyStep $current_step * @param ISurveyQuestionTemplate $question * @param ISurveyAnswer $answer * @return FormField */ public function build(ISurveyStep $current_step, ISurveyQuestionTemplate $question, ISurveyAnswer $answer) { $field = new TextField($question->name(), $question->label()); $field->setValue($question->initialValue()); if ($question->isReadOnly()) { $field->setDisabled(true); } if ($question->isMandatory()) { $field->setAttribute('data-rule-required', 'true'); } if (!is_null($answer)) { $field->setValue($answer->value()); } $this->buildDependantRules($current_step, $question, $field); return $field; }
/** * @param ISurveyStep $current_step * @param ISurveyQuestionTemplate $question * @param ISurveyAnswer $answer * @return FormField */ public function build(ISurveyStep $current_step, ISurveyQuestionTemplate $question, ISurveyAnswer $answer) { $options = array(); if ($question->IsCountrySelector) { $extra_options = array('Worldwide' => 'Worldwide', 'Prefer not to say' => 'Prefer not to say', 'Too many to list' => 'Too many to list'); $options = array_merge($extra_options, CountryCodes::$iso_3166_countryCodes); } else { foreach ($question->Values()->sort('Order') as $val) { $options[$val->ID] = empty($val->Label) ? $val->Value : $val->Label; } } $default_value = $question->DefaultValue(); $field = $question->IsMultiSelect ? new MultiDropdownField($question->name(), $question->label(), $options) : new DropdownField($question->name(), $question->label(), $options); if ($question->isReadOnly()) { $field->setDisabled(true); } if ($question->isMandatory()) { $field->setAttribute('data-rule-required', 'true'); $field->setAttribute('aria-required', 'true'); } if ($default_value) { $field->setValue($default_value->ID); } if (!is_null($answer)) { $field->setValue($answer->value()); } $empty_string = $question->EmptyString; if (!empty($empty_string)) { if ($question->UseChosenPlugin && $question->IsMultiSelect) { $field->setAttribute('data-placeholder', $empty_string); } else { $field->setEmptyString($empty_string); } } $this->buildDependantRules($current_step, $question, $field); if ($question->UseChosenPlugin) { $field->addExtraClass('chosen'); if (count($question->DependsOn()) === 0) { $field->addExtraClass('chosen-visible'); } Requirements::customScript("jQuery(document).ready(function(\$){\n var form = \$('.survey_step_form');\n var form_id = form.attr('id');\n \$('#'+form_id+'_{$question->name()}').chosen({width: '30%'});\n });\n "); } return $field; }
/** * @param ISurveyStep $current_step * @param ISurveyQuestionTemplate $question * @param ISurveyAnswer $answer * @return FormField */ public function build(ISurveyStep $current_step, ISurveyQuestionTemplate $question, ISurveyAnswer $answer) { $options = array(); foreach ($question->Values()->sort('Order') as $val) { $options[$val->ID] = empty($val->Label) ? $val->Value : $val->Label; } $field = new SurveyCheckboxSetField($question->name(), $question->label(), $options, $value = '', $form = null, $emptyString = null, $question); if ($question->isReadOnly()) { $field->setDisabled(true); } if ($question->isMandatory()) { $field->setRequired(); } if (!is_null($answer)) { $field->setValue($answer->value()); } $this->buildDependantRules($current_step, $question, $field); return $field; }
/** * @param ISurveyStep $current_step * @param ISurveyQuestionTemplate $question * @param ISurveyAnswer $answer * @return FormField */ public function build(ISurveyStep $current_step, ISurveyQuestionTemplate $question, ISurveyAnswer $answer) { $options = array(); foreach ($question->Values()->sort('Order') as $val) { $options[$val->ID] = empty($val->Label) ? $val->Value : $val->Label; } $field = new SurveyRankingField($question->name(), $question->label(), $options, $value = '', $form = null, $emptyString = null, $question); if ($question->isReadOnly()) { $field->setDisabled(true); } if ($question->isMandatory()) { $field->setValidationAttribute('data-rule-ranking_required', $field->ID()); $field->setValidationAttribute('data-msg-ranking_required', sprintf('you must select at least one item (%s)', $question->name())); } if (!is_null($answer)) { $field->setValue($answer->value()); } $this->buildDependantRules($current_step, $question, $field); return $field; }
/** * @param ISurveyStep $current_step * @param ISurveyQuestionTemplate $question * @param ISurveyAnswer $answer * @return FormField */ public function build(ISurveyStep $current_step, ISurveyQuestionTemplate $question, ISurveyAnswer $answer) { $options = array(); foreach ($question->Values()->sort('Order') as $val) { $options[$val->ID] = empty($val->Label) ? $val->Value : $val->Label; } $field = new OptionSetField($question->name(), $question->label(), $options); $default_value = $question->getDefaultValue(); if (!is_null($default_value) && $default_value->ID > 0) { $field->setValue($default_value->ID); } if ($question->isReadOnly()) { $field->setDisabled(true); } if ($question->isMandatory()) { $field->setAttribute('data-rule-required', 'true'); } if (!is_null($answer)) { $field->setValue($answer->value()); } $this->buildDependantRules($current_step, $question, $field); return $field; }