Skip to content
Merged
Show file tree
Hide file tree
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
20 changes: 20 additions & 0 deletions app/assets/javascripts/newflow/newflow_ui.js.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -73,5 +73,25 @@ NewflowUi = do () ->
return '<span class="' + cls + '">' + match + '</span>'
)

attachSchoolList: (selector) ->
el = document.querySelector(selector)
listEl = document.getElementById(el.getAttribute('list'))
el.addEventListener('input', ({target}) ->
value = target.value
if (value.length > 3)
fetchSchools(target.value, listEl)
else
listEl.innerHTML = ''
)

schoolQueryUrl = 'https://openstax.org/apps/cms/api/salesforce/schools/?search='
fetchSchools = _.debounce(
(query, listEl) ->
fetch "#{schoolQueryUrl}#{query}", {method: "GET"}
.then (r) -> r.json()
.then (arr) -> arr.map (entry) => "<option value=\"#{entry.name}\"></option>)"
.then (arr) -> listEl.innerHTML = arr.join '\n'
500
)

this.NewflowUi = NewflowUi
4 changes: 3 additions & 1 deletion app/helpers/newflow_form_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,8 @@ def text_field(name:,
numberonly: false,
disabled: false,
described: nil,
required: false)
required: false,
list: nil)
return if excluded?(except: except, only: only)

errors_div = get_errors_div(name: name)
Expand Down Expand Up @@ -76,6 +77,7 @@ def text_field(name:,
onkeyup: onkeyup,
onkeydown: onkeydown,
disabled: disabled,
list: list,
'aria-described-by': described,
'aria-required': required
)
Expand Down
14 changes: 14 additions & 0 deletions app/views/newflow/student_signup/student_signup_form.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,19 @@
%>
</div>

<div class="content control-group">
<%= label_tag :school, I18n.t(:"educator_profile_form.school_name"), class: 'field-label' %>
<%=
form_helper.text_field(
name: :school,
placeholder: I18n.t(:"educator_profile_form.school_name"),
required: false,
list: 'school-list'
)
%>
<datalist id='school-list'>
</datalist>
</div>

<div class="content control-group">
<div id="password-field-container">
Expand Down Expand Up @@ -183,4 +196,5 @@
<script type="text/javascript">
NewflowUi.enableOnChecked('#signup_form_submit_button', '#signup_terms_accepted');
NewflowUi.focusOnFirstErrorItem();
NewflowUi.attachSchoolList(`[name="signup[school]"]`)
</script>
Loading