Example #1
0
 /**
  * Method to get the field input markup for a generic list.
  * Use the multiple attribute to enable multiselect.
  *
  * @return  string  The field input markup.
  *
  * @since   11.1
  */
 protected function getInput()
 {
     $html = array();
     $attr = '';
     // Initialize some field attributes.
     $attr .= !empty($this->class) ? ' class="' . $this->class . '"' : '';
     $attr .= !empty($this->size) ? ' size="' . $this->size . '"' : '';
     $attr .= $this->multiple ? ' multiple' : '';
     $attr .= $this->required ? ' required aria-required="true"' : '';
     $attr .= $this->autofocus ? ' autofocus' : '';
     // To avoid user's confusion, readonly="true" should imply disabled="true".
     if ((string) $this->readonly == '1' || (string) $this->readonly == 'true' || (string) $this->disabled == '1' || (string) $this->disabled == 'true') {
         $attr .= ' disabled="disabled"';
     }
     // Initialize JavaScript field attributes.
     //different onclick handler if field is used in an equalTo statement
     $form = $this->form;
     $label = $form->getFieldAttribute($this->fieldname, 'label');
     //get field defaultvalues
     $model = new VisformsModelVisdatas();
     $datas = $model->getItems();
     $id = JFactory::getApplication()->input->getInt('id', 0);
     //as soon as user inputs are stored we do not allow to change date format
     if (isset($datas) && is_array($datas) && count($datas) > 0) {
         $fname = 'F' . $id;
         foreach ($datas as $data) {
             if (isset($data->{$fname}) && $data->{$fname} != '') {
                 $attr .= ' onchange="formatFieldDateChange(\'' . JText::_("COM_VISFORMS_DATFORMAT_CANNOT_BE_CHANGED_JS") . '\')"';
                 break;
             }
         }
     } else {
         //we allow typefield change
         $attr .= $this->onchange ? ' onchange="' . $this->onchange . '"' : '';
     }
     // Get the field options.
     $options = (array) $this->getOptions();
     // Create a read-only list (no name) with a hidden input to store the value.
     if ((string) $this->readonly == '1' || (string) $this->readonly == 'true') {
         $html[] = JHtml::_('select.genericlist', $options, '', trim($attr), 'value', 'text', $this->value, $this->id);
         $html[] = '<input type="hidden" name="' . $this->name . '" value="' . htmlspecialchars($this->value, ENT_COMPAT, 'UTF-8') . '"/>';
     } else {
         $html[] = JHtml::_('select.genericlist', $options, $this->name, trim($attr), 'value', 'text', $this->value, $this->id);
     }
     return implode($html);
 }
Example #2
0
 public function check()
 {
     $model = new VisformsModelVisdatas();
     $fields = $model->getDatafields();
     $check = true;
     foreach ($fields as $field) {
         $fname = 'F' . $field->id;
         if ($field->typefield == 'date' && isset($this->{$fname}) && $this->{$fname} != "") {
             $formats = explode(';', $field->defaultvalue['f_date_format']);
             $format = $formats[0];
             if (VisformsValidate::validate('date', array('value' => $this->{$fname}, 'format' => $format)) == false) {
                 JFactory::getApplication()->enqueueMessage(JText::sprintf('COM_VISFORMS_DATE_FORMAT_CANNOT_BE_CHANGED', $field->name, $format), 'warning');
                 $check = false;
             }
         }
     }
     return $check;
 }