[['number_of_pieces1'],'number','min'=>$this->min_pieces, 'tooSmall' => 'Minimální náklad je 10 ks.','on' => self::SCENARIO_DEFAULT],
[['number_of_pieces1'],'number','max'=>$this->max_pieces, 'tooBig' => 'Maximální náklad je 1000 ks.','on' => self::SCENARIO_DEFAULT],
[['width','height'], 'compare', 'compareValue' => 2, 'operator' => '>=', 'type' => 'number'],
[['width'], 'number', 'max' => 100,'message' => 'Maximální šířka je 50 cm.' ],
[['height'], 'compare', 'compareValue' => 50, 'operator' => '<=', 'type' => 'number','message' => 'Maximální výška je 50 cm.'],
[['number_of_pieces1','number_of_pieces2','number_of_pieces3'], 'compare', 'compareValue' => 1000, 'operator' => '<=', 'type' => 'number'],
[['width','height',], 'custom_validation','skipOnEmpty' => false, 'skipOnError' => false]
public function custom_validation($attribute, $params,$validator){
if(empty($this->$attribute ) || (!is_numeric($this->$attribute ))){
$validator->addError($this, $attribute, 'Šířka a výška musí být číslo větší než 0');
}
}
public function custom_validation($attribute, $params,$validator){
if(empty($this->$attribute ) || (!is_numeric($this->$attribute ))){
$validator->addError($this, $attribute, 'Šířka a výška musí být číslo větší než 0');
} else {
if( is_numeric($this->width)
&& is_numeric($this->height)
&& ($this->width * $this->height > 500)
) {
if('width' == $attribute) {//aby se nezobrazovalo 2x pri vysce a sirce
$validator->addError($this, $attribute,'Max rozměr je 0.5 m<sup>2</sup>.
Pro velké samolepky prosím přejděte na <a href="https://www.rafo.cz/velke-samolepky">velké samolepky</a>');
}
}
}
}
umber of pieces - /common/models/products/CalculationForm
(pokud je pouze1kalkulace, použije se pouze pravidlo number_pieces1)
[['number_of_pieces1','number_of_pieces2','number_of_pieces3'], 'piecesCriteria'],
public function piecesCriteria()
{ if(empty($this->number_of_pieces1)){
$this->addError('number_of_pieces1','Počet kusů nesmí být prázdný.');
}
if(empty($this->number_of_pieces2)){
$this->addError('number_of_pieces2','Počet kusů nesmí být prázdný.');
}
if(empty($this->number_of_pieces3)){
$this->addError('number_of_pieces3','Počet kusů nesmí být prázdný.');
}
// if(!preg_match('/[0-9]*/',$this->number_of_pieces1)){
}