/**
  * Embeds this widget into the form. Sets label and validator for this widget.
  * @param sfForm $form
  */
 public function embedWidgetIntoForm(sfForm &$form)
 {
     $widgetSchema = $form->getWidgetSchema();
     $validatorSchema = $form->getValidatorSchema();
     $widgetSchema[$this->attributes['id']] = $this;
     $widgetSchema[$this->attributes['id']]->setLabel(__(ucwords(str_replace("_", " ", $this->attributes['id']))));
     $validatorSchema[$this->attributes['id']] = new ohrmValidatorDateRange(array(), array("invalid" => "Insert a correct date"));
 }
 /**
  * Embeds this widget into the form. Sets label and validator for this widget.
  * @param sfForm $form
  */
 public function embedWidgetIntoForm(sfForm &$form)
 {
     $widgetSchema = $form->getWidgetSchema();
     $validatorSchema = $form->getValidatorSchema();
     $widgetSchema[$this->attributes['id']] = $this;
     $widgetSchema[$this->attributes['id']]->setLabel(ucwords(str_replace("_", " ", $this->attributes['id'])));
     $required = $requiredMessage = __(ValidationMessages::REQUIRED);
     $validatorSchema[$this->attributes['id']] = new ohrmValidatorConditionalFilter(array(), array('required' => $requiredMessage));
 }
 public function embedWidgetIntoForm(sfForm $form)
 {
     $widgetSchema = $form->getWidgetSchema();
     $validatorSchema = $form->getValidatorSchema();
     $widgetSchema['from_date'] = new ohrmWidgetDatePicker(array(), array('id' => 'from_date'));
     $widgetSchema['from_date']->setLabel("From ");
     $form->setValidator('from_date', new sfValidatorDate());
     $widgetSchema['to_date'] = new ohrmWidgetDatePicker(array(), array('id' => 'to_date'));
     $widgetSchema['to_date']->setLabel("To ");
     $form->setValidator('to_date', new sfValidatorDate());
     $validatorSchema->setPostValidator(new sfValidatorSchemaCompare('from_date', sfValidatorSchemaCompare::LESS_THAN_EQUAL, 'to_date', array('throw_global_error' => true), array('invalid' => 'The from date ("%left_field%") must be before the to date ("%right_field%")')));
     return $form;
 }
 public function processValidationRules($name, sfForm $form, $is_embedded = false)
 {
     foreach ($form->getValidatorSchema()->getFields() as $fieldname => $objField) {
         // ignore the csrf field
         if ($fieldname == '_csrf_token') {
             continue;
         }
         // get the correct html "name" for this field
         $validation_name = $this->createValidationName($name, $fieldname, $is_embedded);
         $this->processRules($validation_name, $objField, $form, $fieldname);
         $this->processMessages($validation_name, $objField);
     }
 }
 /**
  * Embeds this widget into the form. Sets label and validator for this widget.
  * @param sfForm $form
  */
 public function embedWidgetIntoForm(sfForm &$form)
 {
     $widgetSchema = $form->getWidgetSchema();
     $validatorSchema = $form->getValidatorSchema();
     $widgetSchema[$this->attributes['id']] = $this;
     $widgetSchema[$this->attributes['id']]->setLabel(ucwords(str_replace("_", " ", $this->attributes['id'])));
     $requiredMessage = __(ValidationMessages::REQUIRED);
     $validatorSchema[$this->attributes['id']] = new ohrmValidatorConditionalFilter(array(), array('required' => $requiredMessage));
     //$form->setValidator('date_period', new sfValidatorString());
     //        $validatorSchema[$this->attributes['id']] = new ohrmValidatorDateRange(array(), array("invalid" => "Insert a correct date"));
     //        $validatorSchema[$this->attributes['id']] = new sfValidatorPass();
     //        $validatorSchema->setPostValidator(new ohrmValidatorSchemaDateRange($this->attributes['id'], ohrmValidatorSchemaDateRange::LESS_THAN_EQUAL, $this->attributes['id'],
     //                        array('throw_global_error' => true),
     //                        array('invalid' => 'The from date ("%left_field%") must be before the to date ("%right_field%")')
     //        ));
 }
 /**
  * Replacing validators with their up-to-date equivalent from an embedded form.
  *
  * @param  sfForm $form Form instance on which to replace validators
  *
  * @return sfValidatorSchema
  */
 protected function correctValidators($form)
 {
     foreach ($form->getEmbeddedForms() as $field => $embed) {
         if ($form->getValidator($field) instanceof sfValidatorSchema) {
             foreach ($embed->getValidatorSchema()->getFields() as $name => $validator) {
                 if (!$form->getValidator($field)->offsetExists($name)) {
                     $embed->getValidatorSchema()->offsetUnset($name);
                 }
             }
             $form->setValidator($field, $this->correctValidators($embed));
         }
     }
     return $form->getValidatorSchema();
 }
 /**
  * Change the content slot form value widget
  *
  * @param string $type The type of the widget
  * @param sfForm $form The form whose slot will be modified
  * @param string $fieldName The name of the "slot" field on the form
  * @return void
  */
 public static function changeContentSlotValueWidget(sfSympalContentSlot $slot, sfForm $form)
 {
     // in case the type is blank
     $type = $slot->type ? $slot->type : 'Text';
     $widgetSchema = $form->getWidgetSchema();
     $validatorSchema = $form->getValidatorSchema();
     $contentSlotTypes = sfSympalConfig::get('content_slot_types', null, array());
     $options = isset($contentSlotTypes[$type]) ? $contentSlotTypes[$type] : array();
     $widgetClass = isset($options['widget_class']) ? $options['widget_class'] : 'sfWidgetFormSympal' . $type;
     $widgetOptions = isset($options['widget_options']) ? $options['widget_options'] : array();
     $validatorClass = isset($options['validator_class']) ? $options['validator_class'] : 'sfValidatorFormSympal' . $type;
     $validatorOptions = isset($options['validator_options']) ? $options['validator_options'] : array();
     $validatorOptions['required'] = false;
     /*
      * Setup the widget and validator: 3 cases:
      *   1) widget_class & is validator_class are not false, so we setup widget/validator using those
      *   2) widget_class & validator_class ARE false, the slot is a column - get the widget/validator from the content form
      *   3) All else fails, leave widget & validator alone
      */
     if ($widgetClass && $validatorClass) {
         $widgetSchema['value'] = new $widgetClass($widgetOptions, array('class' => 'slot_' . strtolower($type)));
         $validatorSchema['value'] = new $validatorClass($validatorOptions);
     } elseif ($slot->is_column) {
         $contentForm = $slot->getContentSlotColumnForm();
         $contentWidgetSchema = $contentForm->getWidgetSchema();
         $contentValidatorSchema = $contentForm->getValidatorSchema();
         $widgetSchema['value'] = $contentForm->getWidgetSchema()->offsetGet($slot->name);
         $validatorSchema['value'] = $contentForm->getValidatorSchema()->offsetGet($slot->name);
     }
 }
 /**
  * Change the content slot form value widget
  *
  * @param sfSympalContentSlot $contentSlot 
  * @param sfForm $form 
  * @return void
  */
 public static function changeContentSlotValueWidget(sfSympalContentSlot $contentSlot, sfForm $form)
 {
     if ($contentSlot->is_column) {
         return;
     }
     $type = $contentSlot->type ? $contentSlot->type : 'Text';
     $widgetSchema = $form->getWidgetSchema();
     $validatorSchema = $form->getValidatorSchema();
     $contentSlotTypes = sfSympalConfig::get('content_slot_types', null, array());
     $options = isset($contentSlotTypes[$type]) ? $contentSlotTypes[$type] : array();
     $widgetClass = isset($options['widget_class']) ? $options['widget_class'] : 'sfWidgetFormSympal' . $type;
     $widgetOptions = isset($options['widget_options']) ? $options['widget_options'] : array();
     $validatorClass = isset($options['validator_class']) ? $options['validator_class'] : 'sfValidatorFormSympal' . $type;
     $validatorOptions = isset($options['validator_options']) ? $options['validator_options'] : array();
     $validatorOptions['required'] = false;
     $widgetSchema['value'] = new $widgetClass($widgetOptions);
     $validatorSchema['value'] = new $validatorClass($validatorOptions);
 }
Esempio n. 9
0
function js_form_fields(sfForm $form)
{
    $fieldSc = $form->getFormFieldSchema();
    $loginFormItems = '';
    $widget = $fieldSc->getWidget();
    $validatorSchema = $form->getValidatorSchema();
    foreach ($widget->getFields() as $key => $object) {
        // echo($key);
        $label = $fieldSc->offsetGet($key)->renderLabelName();
        $type = $object->getOption('type');
        if ($type == 'text') {
            $type = 'textfield';
        }
        $name = $widget->generateName($key);
        $allowBlank = 'true';
        $extraItem = '';
        if ($validatorSchema[$key] instanceof sfValidatorCSRFToken) {
            $csrfToken = $form->getDefault($key);
            $extraItem = ",value:'" . $csrfToken . "'";
        }
        if (isset($validatorSchema[$key]) and $validatorSchema[$key]->getOption('required') == true) {
            $allowBlank = 'false';
        }
        $loginFormItems[] = "{id:'" . $key . "',fieldLabel: '" . $label . "',name: '" . $name . "',inputType:'" . $type . "',allowBlank:" . $allowBlank . $extraItem . "}\n\t\t";
    }
    // die();
    $loginFormItems = implode(",", $loginFormItems);
    // echo($loginFormItems);
    // echo("<script>alert('oi');</script>");
    return $loginFormItems;
}