Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 18 additions & 15 deletions app/views/coursesurveys/merge_instructors.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -4,23 +4,26 @@

<script type="text/javascript">
profname = function(prof) { return prof.name; }

$(document).ready( function() {
$.ajax({ url: <%= raw coursesurveys_instructor_ids_path.inspect %>,
success: function(data) {
<%-[0,1].each do |i|-%>
$('#ibox<%=i%>').
autocomplete(data, {formatItem: profname} ).
result( function(event,item) {
$('#id_<%=i%>')[0].value = item.id;
$('#ibox<%=i%>')[0].disabled = true;
});
$('#ibox<%=i%>').keypress(function(event){if(event.which == 13) event.preventDefault();});
<%-end-%> }
});
$("#submit").click( function() {
});

$.ajax({
url: <%= raw coursesurveys_instructor_ids_path.inspect %>,
success: function(data) {
[0,1].map(function(i) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah...maybe this wasn't the best way of curing the problem. We might as well jQuery all the way.
Instead of using the ID selectors, a class applied to the inputs and the hidden fields might be a better idea. Say the fields currently id'd as iboxN had the class instructor-name. You could then write:

$('.instructor-name').each(function() {
  // ... your code here, where this refers to each of the elements with the class 'instructor-name'
});

$('#ibox' + i).autocomplete(data, {formatItem: profname}).result(function(event, item) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This would then become $(this).autocomplete(....

$('#id_' + i)[0].value = item.id;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If element with the id_N id had the class instructor-id, you could write

$(this).parent().find('.instructor-id').attr('value', item.id);

$('#ibox' + i)[0].disabled = true;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Definitely use attr instead of peeking inside the mystical superpowered jQuery object, which may just happen to be (okay, is) some kind of array, which is why this worked.

$(this).attr('disabled', true);

});
$('#ibox' + i).keypress(function(event) {
/* Prevent return button from submitting form */
if (event.which == 13) {
return false;
}
});
});
}
});
});
</script>

<style type="text/css">
Expand Down