Skip to content

Commit

Permalink
Fixed the accessible jQuery validations issue. Someone please mark it…
Browse files Browse the repository at this point in the history
… resolved in issue queue as well. Before that please test this with IE. I have tested only with NVDA and Firefox.
  • Loading branch information
sidnc86 committed Sep 15, 2013
1 parent b2842b9 commit 97cdcc5
Showing 1 changed file with 63 additions and 11 deletions.
74 changes: 63 additions & 11 deletions app/assets/javascripts/topics.js.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,69 @@
# All this logic will automatically be available in application.js.
# You can use CoffeeScript in this file: http://jashkenas.github.com/coffee-script/
$(document).ready ->
errorElements = $('.content').find('.help-inline').prev()
ul = $('<ul id="errorlist"></ul>')
errorElements.each (i) ->
span = $(this).next()
labelText = $(this).parent().parent().find('label')
$(' <li> <a href="#' + $(this).attr('id') + '" class="errorlink" >' + labelText.text() + ' ' + '(' + span.text() + ')' + '</a></li>').appendTo(ul)
$('#errorcontainer').html(ul)
$('.errorlink').bind 'click', (e)->
sid = $(this).attr('href').substr(1, $(this).attr('href').length-1)
e.stopPropagation
$('input[id="' + sid + '"]').focus()


#error elements test
#alert("error elements:" + $('.content:first .help-inline').size())
#get the errorElements
errorElements = $('.content:first .help-inline')

#validate only if errors exist
if(errorElements.length > 0)
#test where error container is
#$("#errorcontainer").html("Here I am")

#ul element as container for error summary
errorSummaryContainer = $(document.createElement("ul"))
errorSummaryContainer.attr("id","errorlist")

#append error summary to error container
$("#errorcontainer").append(errorSummaryContainer)

#Iterate through the error elements to create summary
#test individual error elements
#i = 0
errorElements.each ->
#Test results for each individual error element
#alert("this is error number " + ++i)

#individual participents
errorElement = $(this)#Note this singular
inputElement = errorElement.prev()#preventing another call to $(this)
labelElement = errorElement.parent().prev()#again preventing another call to $(this)

#test whether we have all the above three elements
#alert(labelElement.text() + ":" + labelElement.attr("for") + ":" + inputElement.attr("id") + ":" + errorElement.text())
#test to get only label text without the "*" sign
#alert(labelElement.contents().last().text())

#Error string
labelText = labelElement.contents().last().text()#without the "*"
errorString = labelText + "(" + errorElement.text() + ")"#e.g. First Name(Can't be blank)

#anchor element for error string
anchorElement = $(document.createElement("a"))
#Siddhant thinks that focussing input element can work even without the href in action
anchorElement.attr("href","javascript:void(0)")
anchorElement.addClass("errorlink")
anchorElement.text(errorString)
anchorElement.click ->
$("#" + inputElement.attr("id")).focus()

#listElement for anchor element
listElement = $(document.createElement("li"))
errorSummaryContainer.append(listElement)
listElement.append(anchorElement)

#End iteration

#focus the first anchor of errors and announce the same to screen reader user
$(".errorlink:first").focus()
#Still need javascript statements to generate a hidden element with ARIA alert/asert/whatever
#that tells "There are errors. you are on first error. Press tab and shift tab to move between errors. Hit enter to resolve it."

#End if errors


window.nestedFormEvents.insertFields = (content, assoc, link) ->
$(content).insertBefore(link)
Expand Down

0 comments on commit 97cdcc5

Please sign in to comment.