Search code examples
phpjqueryhtmlcakephpcakephp-2.x

Cakephp 2.X disable/enable syntax


I'm using the following example http://jsfiddle.net/nc6NW/1/

Yet when I change this to formhelper syntax the Jquery does not re-enable the disabled save functionality. How does one remove this attribute given this function

<div id="newArticleForm">
    <?php
    echo $this->Form->create('Post', array('action' => 'add'));
    echo $this->Form->input('article_title',array('type' => 'text', 'id'=>'ArticleHeader','div'=>false,'label'=>false,'class'=>'centertext',"placeholder"=>"Article Header"));
    echo $this->Html->para(null,'<br>', array());
    echo $this->Form->input('article_link',array('type' => 'text', 'id'=>'ArticleLink','div'=>false,'label'=>false,'class'=>'centertext',"placeholder"=>"Article Link"));
    echo $this->Html->para(null,'<br>', array());
    echo $this->Form->button('Cancel', array('type' => 'reset'), array('inline' => false));
    echo $this->Form->button('Save', array('type' => 'submit', 'disabled'=>true), array('inline' => false));

    echo $this->Form->end();
    ?>
</div>
<script>
$(':text').keyup(function() {
    if($('#ArticleHeader').val() != "" && $('#ArticleLink').val() != "") {
        $('#submit').removeAttr('disabled');
    } else {
        $('#submit').attr('disabled', true);
    }
});
</script>

Solution

  • Solved it, sorry for wasting everyone's time submit had the wrong identifier, needed a colon not a hash. i.e.

    $(':text').keyup(function() {
        if($('#ArticleHeader').val() != "" && $('#ArticleLink').val() != "") {
            $(':submit').removeAttr('disabled');
        } else {
            $(':submit').attr('disabled', true);
        }
    });