Yii2比较验证不起作用

时间:2015-12-23 11:44:18

标签: javascript php yii2

我的问题是比较验证无法正常工作。如果我的min_bid_amount = 100min_buy_amount=1000正在运作。但是min_bid_amount = 500min_buy_amount=1000会出现问题。它还给了我错误信息。

这是我的模型规则

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']
    ];
}

非常感谢任何帮助。我认为JS不会将其转换为int类型值。那我该怎么办呢?

1 个答案:

答案 0 :(得分:6)

您应该将type验证更改为number

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