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 static function replaceValidators(sfForm $form)
 {
     foreach ($form->getWidgetSchema()->getFields() as $name => $widget) {
         if ($widget instanceof mtWidgetFormInputDate) {
             $form->setValidator($name, self::getDateValidator());
         } elseif ($widget instanceof sfWidgetFormFilterDate) {
             $form->getValidator($name)->setOption("from_date", self::getDateValidator(array("required" => false)));
             $form->getValidator($name)->setOption("to_date", self::getDateValidator(array("required" => false)));
         }
         if ($name == "attachment") {
             $form->setValidator($name, new sfValidatorFile(array("required" => false, "path" => sfConfig::get("sf_upload_dir"))));
         } elseif ($name == "email") {
             $form->setValidator($name, new sfValidatorEmail());
         }
     }
 }
 /**
  * Embeds this widget into the form.
  * @param sfForm $form
  */
 public function embedWidgetIntoForm(sfForm &$form)
 {
     $widgetSchema = $form->getWidgetSchema();
     $widgetSchema[$this->attributes['id']] = $this;
     $label = ucwords(str_replace("_", " ", $this->attributes['id']));
     $widgetSchema[$this->attributes['id']]->setLabel($label);
     $form->setValidator($this->attributes['id'], new sfValidatorPass());
 }
 /**
  * Just to make sure every time a form is embedded, the 'remove' widgets
  * are added. They are needed in the deleting process
  */
 public function embedForm($name, sfForm $form, $decorator = null)
 {
     if ($form instanceof sfFormDoctrine) {
         $form->setWidget('remove', new sfWidgetFormInputHidden(array(), array('class' => 'remove')));
         $form->setValidator('remove', new sfValidatorPass());
     }
     parent::embedForm($name, $form, $decorator);
 }
 /**
  * Embeds this widget into the form. Sets label and validator for this widget.
  * @param sfForm $form
  */
 public function embedWidgetIntoForm(sfForm &$form)
 {
     $widgetSchema = $form->getWidgetSchema();
     $widgetSchema[$this->attributes['id']] = $this;
     $label = ucwords(str_replace("_", " ", $this->attributes['id']));
     $validator = new sfValidatorChoice(array('choices' => array_keys($this->subDivisionList)));
     if ($this->attributes['required'] == "true") {
         $label .= "<span class='required'> * </span>";
     }
     $widgetSchema[$this->attributes['id']]->setLabel($label);
     $form->setValidator($this->attributes['id'], $validator);
 }
 /**
  * Embeds this widget into the form. Sets label and validator for this widget.
  * @param sfForm $form
  */
 public function embedWidgetIntoForm(sfForm &$form)
 {
     $widgetSchema = $form->getWidgetSchema();
     $widgetSchema[$this->attributes['id']] = $this;
     $label = ucwords(str_replace("_", " ", $this->attributes['id']));
     $validator = new sfValidatorString();
     if ($this->attributes['required'] == "true") {
         $label .= "<span class='required'> * </span>";
         $validator = new sfValidatorString(array('required' => true), array('required' => 'No employees added to the system'));
     }
     $widgetSchema[$this->attributes['id']]->setLabel($label);
     $form->setValidator($this->attributes['id'], $validator);
 }
 /**
  * Embeds this widget into the form. Sets label and validator for this widget.
  * @param sfForm $form
  */
 public function embedWidgetIntoForm(sfForm &$form)
 {
     $widgetSchema = $form->getWidgetSchema();
     $widgetSchema[$this->attributes['id']] = $this;
     $label = __(ucwords(str_replace("_", " ", $this->attributes['id'])));
     $validator = new sfValidatorString(array('required' => false));
     if ($this->attributes['required'] == "true") {
         $label .= "<span class='required'> * </span>";
         $validator = new sfValidatorString(array('required' => true), array('required' => 'Add a project to view'));
     }
     $widgetSchema[$this->attributes['id']]->setLabel($label);
     $form->setValidator($this->attributes['id'], $validator);
 }
 /**
  * Embeds this widget into the form. Sets label and validator for this widget.
  * @param sfForm $form
  */
 public function embedWidgetIntoForm(sfForm &$form)
 {
     $requiredMess = 'Select a gender type';
     $widgetSchema = $form->getWidgetSchema();
     $widgetSchema[$this->attributes['id']] = $this;
     $label = ucwords(str_replace("_", " ", $this->attributes['id']));
     $validator = new sfValidatorString();
     if (isset($this->attributes['required']) && $this->attributes['required'] == "true") {
         $label .= "<span class='required'> * </span>";
         $validator = new sfValidatorString(array('required' => true), array('required' => $requiredMess));
     }
     $widgetSchema[$this->attributes['id']]->setLabel($label);
     $form->setValidator($this->attributes['id'], $validator);
 }
 /**
  * Embeds this widget into the form. Sets label and validator for this widget.
  * @param sfForm $form
  */
 public function embedWidgetIntoForm(sfForm &$form)
 {
     $widgetSchema = $form->getWidgetSchema();
     $widgetSchema[$this->attributes['id']] = $this;
     $label = ucwords(str_replace("_", " ", $this->attributes['id']));
     $required = false;
     if (isset($this->attributes['required']) && $this->attributes['required'] == "true") {
         $label .= "<span class='required'> * </span>";
         $required = true;
     }
     $requiredMess = __(ValidationMessages::REQUIRED);
     $validator = new sfValidatorString(array('required' => $required), array('required' => $requiredMess));
     $widgetSchema[$this->attributes['id']]->setLabel($label);
     $form->setValidator($this->attributes['id'], $validator);
 }
Esempio n. 10
0
 /**
  * Embeds this widget into the form. Sets label and validator for this widget.
  * @param sfForm $form
  */
 public function embedWidgetIntoForm(sfForm &$form)
 {
     $userObj = sfContext::getInstance()->getUser()->getAttribute("user");
     $projectList = $userObj->getActiveProjectList();
     $requiredMess = __('Select a project');
     if ($projectList == null) {
         $requiredMess = __("No Projects Defined");
     }
     $widgetSchema = $form->getWidgetSchema();
     $widgetSchema[$this->attributes['id']] = $this;
     $label = __(ucwords(str_replace("_", " ", $this->attributes['id'])));
     $validator = new sfValidatorString();
     if ($this->attributes['required'] == "true") {
         $label .= "<span class='required'> * </span>";
         $validator = new sfValidatorString(array('required' => true), array('required' => $requiredMess));
     }
     $widgetSchema[$this->attributes['id']]->setLabel($label);
     $form->setValidator($this->attributes['id'], $validator);
 }
Esempio n. 11
0
 /**
  * Takes a form and configures each image's widget.
  * 
  * This is one of only 2 methods the user needs to call manually (the other being configureJCropWidgets)
  * Should be called from the form's configure() method
  * 
  * @param sfForm $form
  */
 public function configureJCropValidators($form)
 {
     foreach ($this->_options['images'] as $fieldName) {
         $form->setValidator($fieldName . '_delete', new sfValidatorPass());
         $form->setValidator($fieldName, new sfValidatorFile(array('required' => false, 'path' => $this->getImageDir(), 'mime_types' => 'web_images'), array('mime_types' => 'Unsupported image type (%mime_type%)')));
     }
 }
 /**
  * Add a validated image upload field to a form.
  * 
  * @param sfForm $form        Form to modify
  * @param string $field_name  Name of the image upload field, default 'image'  
  */
 public static function addImageField($form, $field_name = 'image')
 {
     $form->setWidget($field_name, new sfWidgetFormInputFile());
     $form->setValidator($field_name, new sfValidatorImageFile(self::getValidatorOptions(), self::getValidatorMessages()));
 }
 /**
  * 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 theme widget to be dropdown of themes
  *
  * @param sfForm $form 
  * @return void
  */
 public static function changeThemeWidget(sfForm $form)
 {
     $array = self::getThemeWidgetAndValidator();
     $form->setWidget('theme', $array['widget']);
     $form->setValidator('theme', $array['validator']);
 }
 /**
  * Embeds this widget into the form. Sets label and validator for this widget.
  * @param sfForm $form
  */
 public function embedWidgetIntoForm(sfForm &$form)
 {
     $activeProjectFound = false;
     $userRoleManager = sfContext::getInstance()->getUserRoleManager();
     $projectList = $userRoleManager->getAccessibleEntities('Project');
     foreach ($projectList as $project) {
         if ($project->getIsDeleted() != 0) {
             $activeProjectFound = true;
             break;
         }
     }
     $requiredMess = __('Select a project');
     if (!$activeProjectFound) {
         $requiredMess = __("No Projects Defined");
     }
     $widgetSchema = $form->getWidgetSchema();
     $widgetSchema[$this->attributes['id']] = $this;
     $label = __(ucwords(str_replace("_", " ", $this->attributes['id'])));
     $validator = new sfValidatorString();
     if ($this->attributes['required'] == "true") {
         $label .= "<span class='required'> * </span>";
         $validator = new sfValidatorString(array('required' => true), array('required' => $requiredMess));
     }
     $widgetSchema[$this->attributes['id']]->setLabel($label);
     $form->setValidator($this->attributes['id'], $validator);
 }