0

How can I define radio buttons for a model field.

class Model_Campaign extends Model_Table {
  public $entity_code = 'campaign';
  function init() {
    parent::init();

    $this->addField('nombres')->mandatory(TRUE);
    $this->addField('email')->mandatory(TRUE);
    $this->addField('celular')->mandatory(TRUE);
    $this->addField('ciudad');
    $this->addField('operador')->mandatory(TRUE);
  }
}

I want to 'operador' field shows like radiobuttons, and I want to 'celular' field only accepts numeric values.

Braulio Soncco
  • 353
  • 1
  • 4
  • 20

2 Answers2

1

1# about radiobuttons

So, if you want to have radio buttons, this implies that either you have static list of values or you are referencing other model, thus do following:

a: $this->hasOne("Operador", "operador"), given you have Model_Operador
b: $this->addField("operador")->datatype("list")->listData(array());

this will make drop down to appear. If you want to have radio buttons: add ->display("radio");

2# validation - read documentation: http://agiletoolkit.org/doc/form/validation

->validateField('filter_var($this->get(), FILTER_VALIDATE_INT)');

e.g.

$this->addField("fieldx")->validateField('filter_var($this->get(), FILTER_VALIDATE_INT)');

n.b. make sure you use atk4.2 (master branch in github)

more filters: http://php.net/manual/en/filter.filters.validate.php

jancha
  • 4,916
  • 1
  • 24
  • 39
  • Thank you jancha, but how can I define the validator in the model? `$this->addField('email')->mandatory(TRUE) ->validateField('filter_var($this->get(), FILTER_VALIDATE_INT)');` doesn't work – Braulio Soncco Apr 23 '12 at 11:26
  • just add that validateField() into the model init block for the field that needs the validation. – jancha Apr 23 '12 at 11:28
1
$this->addRadioAttribute("gender",array("male","female"));

here: gender is a field name, male and female are values.

Tisho
  • 8,320
  • 6
  • 44
  • 52
ramesh
  • 11
  • 1