setRequired

Developers
Sano
2012-04-18
2013-05-15
  • Sano
    Sano
    2012-04-18

    Hello everyone!
    Does anybody know how to use "setRequiredField" property? I mean where and when the application uses this condition, and also it's interesting how exactly it is used (simply nonempty condition?)?
    Best regards!

     
  • Sano
    Sano
    2012-04-18

    P.S.  I know that everything is kinda obvious, BUT i use setRequired on the field I built, and then call "validateFields" user pushes a button, and application just passes the empty value

     
  • The required property is verified on the saveRow() event. validateFields() is a function that return true if all the 'required' fields are not empty. Must be used as a conditioner before saveRow().

    If you need validate something after exit the field, must be use validators, Search in the forum for examples.

    Eddie (Edgar Joel Rodríguez Ávalos)

     
  • croaker___
    croaker___
    2012-04-18

    If you can post some code we might be able to see where the problem is.

     
  • Sano
    Sano
    2012-04-19

    Thank you for answering yet it didn't help, the most obvious example I have is "Products catalogue"… I tried to repeat but it didn't work out. So…..
    I have somathing like this:

    $this->build("p4a_field", "number_f")
                    ->setType("text")
                    ->setInputMask($this->masks_for_numbers);

    $this->setRequiredField($this->number_f);

    $this->build("p4a_button", "save_but")
                    ->setWidth(120)               
                    ->implement("onclick",$this,"save_row");

    and then :

    public function save_row()
        {
    $this->validateFields();
    //getting values and then
                    P4A::singleton()->CD->newRow();
       P4A::singleton()->CD->saveRow(array("PhoneNum"=>$number,"Debt"=>intval($debt*100),"Company"=>$company));
        }

    Buuuuuuuuuuuuuuut, it just does nothing, and I so much wanted it looked like in "Products catalogue" like red rectangulars… ^_^

     
  • Sano
    Sano
    2012-04-23

    I just wonder if I can use created fields for the SetRequired or i must use like $this->fields ,i.e. loaded???