-
Notifications
You must be signed in to change notification settings - Fork 11
Replaced Rails loop with JavaScript map to handle instructor merges #26
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -6,21 +6,22 @@ | |
| 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-%> } | ||
| }); | ||
| success: function(data) { | ||
| [0,1].map(function(i) { | ||
| $('#ibox' + i). | ||
| autocomplete(data, {formatItem: profname} ). | ||
| result( function(event,item) { | ||
| $('#id_' + i)[0].value = item.id; | ||
| $('#ibox' + i)[0].disabled = true; | ||
| }); | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nitpicks about the indentation and lane breaks here:
|
||
| $('#ibox' + i).keypress(function(event){if(event.which == 13) event.preventDefault();}); | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is pretty difficult to read and I don't actually understand what it's doing. Also, are you sure you want |
||
| }); | ||
| } | ||
| }); | ||
| $("#submit").click( function() { | ||
| }); | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It's not part of your changes, but what is the point of this? If it serves no function, can you delete it? |
||
|
|
||
| }); | ||
| }); | ||
| </script> | ||
|
|
||
| <style type="text/css"> | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I believe a
forloop is more conventional in Javascript.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
With a for loop, I ran into weird issues regarding JavaScript closures. That is, the counter variable of the for loop would be incremented again (i = 2), and then a subsequent $("#ibox1").autocomplete would attempt to update #id_2 and #ibox2, which don't exist.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you give an example of what you were trying with a
forloop?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I believe my original attempt went something like this:
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I played around with this code in the console, and I see why you ran into the
i = 2problem. The variableireferenced from within the autocomplete event handler is bound to theifrom the same scope as theforloop, but when the event handler is actually called, the value ofihas changed. Can we change this so that we can look up theidandiboxelements given just theiboxelement viathisorevent.target?