$type, $name, $label = '',
$attributes = '', $required = FALSE, $extra = NULL
) {
+ if ($type === 'radio') {
+ CRM_Core_Error::deprecatedFunctionWarning('CRM_Core_Form::addRadio');
+ }
// Fudge some extra types that quickform doesn't support
$inputType = $type;
if ($type == 'wysiwyg' || in_array($type, self::$html5Types)) {
// @see https://docs.civicrm.org/dev/en/latest/framework/ui/#date-picker
if ($type === 'datepicker') {
$attributes = $attributes ?: [];
- if (!empty($attributes['format'])) {
- $dateAttributes = CRM_Core_SelectValues::date($attributes['format'], NULL, NULL, NULL, 'Input');
+ if (!empty($attributes['formatType'])) {
+ $dateAttributes = CRM_Core_SelectValues::date($attributes['formatType'], NULL, NULL, NULL, 'Input');
if (empty($extra['minDate']) && !empty($dateAttributes['minYear'])) {
$extra['minDate'] = $dateAttributes['minYear'] . '-01-01';
}
unset($extra['option_context']);
}
- $this->addRequiredAttribute($required, $extra);
$element = $this->addElement($type, $name, CRM_Utils_String::purifyHTML($label), $attributes, $extra);
if (HTML_QuickForm::isError($element)) {
CRM_Core_Error::statusBounce(HTML_QuickForm::errorMessage($element));
return self::$_template->get_template_vars($name);
}
- /**
- * jQuery validate prefers to see a validation rule as a class (eg. "required").
- * We can't add a class at the quickform level but jQuery validate also works with HTML5:
- * HTML5 validation requires a separate attribute "required".
- *
- * @param $required
- * @param $attributes
- */
- private function addRequiredAttribute($required, $attributes) {
- // Ideally we do this by adding "required" as a class on the radio but we can't
- // But adding the attribute "required" directly to the element also works.
- $required ? $attributes['required'] = 1 : NULL;
- }
-
/**
* @param string $name
* @param $title
$allowClear = !empty($attributes['allowClear']);
unset($attributes['allowClear']);
$attributes['id_suffix'] = $name;
- // For jquery validate we need to flag the actual radio as required.
- $this->addRequiredAttribute($required, $attributes);
foreach ($values as $key => $var) {
$optAttributes = $attributes;
if (!empty($optionAttributes[$key])) {
}
}
}
- $options[] = $this->createElement('radio', NULL, NULL, $var, $key, $optAttributes);
+ $element = $this->createElement('radio', NULL, NULL, $var, $key, $optAttributes);
+ if ($required) {
+ $element->setAttribute('required', TRUE);
+ }
+ $options[] = $element;
}
$group = $this->addGroup($options, $name, $title, $separator);
$required,
['class' => 'crm-select2']
);
- $attributes = ['format' => 'searchDate'];
+ $attributes = ['formatType' => 'searchDate'];
$extra = ['time' => $isDateTime];
$this->add('datepicker', $fieldName . $from, ts($fromLabel), $attributes, $required, $extra);
$this->add('datepicker', $fieldName . $to, ts($toLabel), $attributes, $required, $extra);