javascript - Link not working after render partial js -
so want re-render table after updating event.
i this:
## controller: respond_to |format| if schedule_child.save sql = "schedules.doctor_id = ? , schedules.location_id = ? , schedule_children.start_time >= ? , schedule_children.start_time <= ?" @schedules = schedulechild.joins(:schedule).where(sql, current_doctor.id, session[:location_id], time.now, time.now + 7.days).order(start_time: :asc).page(params[:page]).per(7) format.js {render :layout => false} end end
my js.erb:
$('#schedules').html( "<%= escape_javascript( render "schedules" ) %>" );
my view:
%a.status_link.btn.btn-success.btn-sm{"data-href" => set_schedule_status_path(location_id: session[:location_id] ,id: schedule.id), :style => "#{schedule.is_away ? 'display: none' : '' }", :id => "#{schedule.id}", :remote => "true"} %i.fa.fa-check-square-o %span available
the table rendered cannot click link in view. did wrong? :)
the use of "data-href"
link instead of "href"
requires additional javascript make link available. have javascript in place , calling on document.ready
, apply javascript logic on every link data property "data-href".
if case have 4 options (just guesses don't know logic data-href using):
- use
href
instead ofdata-href
- call logic enables link in js.erb (after replaced table)
- call logic enables link on
document.ready
,ajaxstop
- define logic on parent node exists
$('body').on('click', 'a[data-href]', ...
Comments
Post a Comment