rails上のjsファイル内にて、coffee scriptで下記のように書いたのですが、、
上の方のdisabledは反映されるのですが、下のdisabledが反映されません。
上の内容と下の内容を入れ替えると、常に上の方のdisableのみ反映されます。
button1とbutton2ともtypeはsubmitです。
2つとも検索ボタンで、何か文字や数字を記載しないと、disableの状態を保持しておきたいのですが、常に片方しかdisabledになりません。。
なお、2つのボタンは別のviewファイルで、違うcontrollerの下です。
よろしくお願い致します。
$ -> if $('#code_product_field input').val().length == 0 $('#button_1').attr 'disabled', true $('#code_product_field input').on 'keydown keyup keypress change', -> if $(this).val().length > 0 $('#button_1').prop 'disabled', false else $('#button_1').prop 'disabled', true return return $ -> if $('#tariff_item_field input').val().length == 0 $('#button_2').prop 'disabled', true $('#tariff_item_field input').on 'keydown keyup keypress change', -> if $(this).val().match(/^\d+$/) and $(this).val().length == 6 $('#button_2').prop 'disabled', false else $('#button_2').prop 'disabled', true return return
あなたの回答
tips
プレビュー