lundi 29 février 2016

How to ensure previous checkbox is checked to enable current checkbox

I am trying to perform validations on coffeescript to enable the checkbox only if the previous checkbox is checked for a list of tasks. My current codes are below.

    - @job.tasks.each do |task|
     - if (not @job.started?) || @job.final_price.zero?
      .checkbox
     - elsif task.completed?
      .checkbox.enable
        i.checkmark.icon
     -else
      = link_to '', complete_gogetters_task_path(task), method: 'put', class: 'checkbox enable', id:"ck_submit1", onclick: 'Form_one()', num: task.id

How to I find the previous task? I want to do something like:

    - @job.tasks.each do |task|
     - if (not @job.started?) || @job.final_price.zero? || task.prev.not_completed?
      .checkbox
     - elsif task.completed?
      .checkbox.enable
        i.checkmark.icon
     -else
      = link_to '', complete_gogetters_task_path(task), method: 'put', class: 'checkbox enable', id:"ck_submit1", onclick: 'Form_one()', num: task.id

Appreciate any help. Thanks!




Aucun commentaire:

Enregistrer un commentaire