예제 #1
0
 /**
  * Echos a list of custom dropdowns
  *
  * This method is called via AJAX on the field editor to get a list of dropdowns
  * or modules to be used for modifying the type of field.
  */
 public function actionGetFieldType()
 {
     if (isset($_POST['Fields']['type'])) {
         $field = new Fields();
         $field->attributes = $_POST['Fields'];
         $type = $_POST['Fields']['type'];
         $model = new AmorphousModel();
         $model->addField($field, 'customized_field');
         $this->renderPartial('fieldDefault', array('field' => $field, 'dummyModel' => $model, 'type' => $type, 'echoScripts' => true));
     }
 }
예제 #2
0
파일: Fields.php 프로젝트: shayanyi/CRM
 /**
  * Check that the default value is appropriate given the type of the field.
  * 
  * @param string $attribute
  * @param array $params
  */
 public function validDefault($attribute, $params = array())
 {
     if ($this->fieldName == '') {
         return;
     }
     // Nothing is possible without the field name. Validation will fail for it accordingly.
     // Use the amorphous model for "proxy" validation, and use a "dummy"
     // field model (because we'll need to set the name differently to make
     // things easier on ourselves, given how user input for field name might
     // not be appropriate for a property name)
     $dummyModel = new AmorphousModel();
     $dummyField = new Fields();
     foreach ($this->attributes as $name => $value) {
         $dummyField->{$name} = $value;
     }
     $dummyField->fieldName = 'customized_field';
     $dummyModel->scenario = 'insert';
     $dummyModel->addField($dummyField, 'customized_field');
     $dummyModel->setAttribute('customized_field', $this->{$attribute});
     $dummyModel->validate();
     if ($dummyModel->hasErrors('customized_field')) {
         foreach ($dummyModel->errors['customized_field'] as $error) {
             $this->addError($attribute, str_replace($dummyField->attributeLabel, $dummyField->getAttributeLabel($attribute), $error));
         }
     }
 }