If input field is empty, disable submit button

后端 未结 5 1968
不知归路
不知归路 2020-12-04 19:59

I\'m trying to disable submit button if the user hasn\'t provided any text.

At first sight it looks that everything works just fine, but if user types some text, th

5条回答
  •  日久生厌
    2020-12-04 20:36

    For those that use coffeescript, I've put the code we use globally to disable the submit buttons on our most widely used form. An adaption of Adil's answer above.

    $('#new_post button').prop 'disabled', true
    $('#new_post #post_message').keyup ->
        $('#new_post button').prop 'disabled', if @value == '' then true else false
        return
    

提交回复
热议问题