uiTeam324
uiTeam324

Reputation: 1245

Yii2 compare validation not working

My problem is compare validation is not working correctly. If my min_bid_amount = 100 and min_buy_amount=1000, it's working. But problem occurs when min_bid_amount = 500 and min_buy_amount=1000. It also gives me error message.

Here is my model rule

public function rules()
{
    return [
        [['min_bid_amount','min_buy_amount'], 'number'],
        ['min_buy_amount', 'compare','compareAttribute'=>'min_bid_amount','operator'=>'>',
        'message'=>'Buying amount should be bigger than bid amount'],
        [['auction_start_date', 'auction_end_date', 'created'], 'safe'],
        [['id_product','min_bid_amount','min_buy_amount'], 'required']
    ];
}

Any help would be very much appreciated. I think JS does not convert it into int type value. So how could I do that?

Upvotes: 2

Views: 2943

Answers (1)

SilverFire
SilverFire

Reputation: 1592

You should change the type of validation to number:

    ['min_buy_amount', 'compare','compareAttribute'=>'min_bid_amount','operator'=>'>',
    'message'=>'Buying amount should be bigger than bid amount', 'type' => 'number'],

Upvotes: 8

Related Questions