Skip to content

Commit

Permalink
validation issue has been fixed for IE
Browse files Browse the repository at this point in the history
  • Loading branch information
vishalpawle committed Sep 19, 2013
2 parents 900a7ce + 97cdcc5 commit 44d0da8
Show file tree
Hide file tree
Showing 12 changed files with 82 additions and 39 deletions.
13 changes: 0 additions & 13 deletions app/assets/javascripts/levels.js.coffee
Original file line number Diff line number Diff line change
@@ -1,16 +1,3 @@
# Place all the behaviors and hooks related to the matching controller here.
# All this logic will automatically be available in application.js.
# You can use CoffeeScript in this file: http://jashkenas.github.com/coffee-script/
# Place all the behaviors and hooks related to the matching controller here.
# 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') + '" onclick=" " >' + labelText.text() + ' ' + '(' + span.text() + ')' + '</a></li>').appendTo(ul)
$('#errorcontainer').html(ul)
$("#bonus_round_unlocked").click ->
$("#bonus_round").show()
25 changes: 1 addition & 24 deletions app/assets/javascripts/topics.js.coffee
Original file line number Diff line number Diff line change
@@ -1,27 +1,4 @@
# Place all the behaviors and hooks related to the matching controller here.
# 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 id="will"> <a href="#' + $(this).attr('id') + '" class="errorlink" >' + labelText.text() + ' ' + '(' + span.text() + ')' + '</a></li>').appendTo(ul)
# $('.errorlink').click ->
# alert('hello')

# $('#errorcontainer').html(ul)

# $(".errorlink").bind "click", (e) ->
#   alert('hello')
$(' <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()

$(document).ready ->
window.nestedFormEvents.insertFields = (content, assoc, link) ->
$(content).insertBefore(link)
if assoc == "contents"
Expand Down
1 change: 1 addition & 0 deletions app/assets/javascripts/users.js.coffee
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
alert("hello")
errorElements = $(document).find('.help-inline').prev()
ul = $('<ul id="errorlist"></ul>')
errorElements.each (i) ->
Expand Down
62 changes: 62 additions & 0 deletions app/assets/javascripts/validations.js.coffee
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
# Place all the behaviors and hooks related to the matching controller here.
# 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 ->
# alert("hello")
#error elements test
#alert("error elements:" + $('.content:first .help-inline').size())
#get the errorElements
errorElements = $(document).find('.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 ->
alert("hello")
$("#" + inputElement.attr("id")).focus()

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


#End iteration
$(".errorlink:first").focus()
4 changes: 4 additions & 0 deletions app/views/home/_nominate_form.html.haml
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
- content_for :javascript do
= javascript_include_tag 'validations'
= simple_form_for @nominate, url: nominate_path(@nominate), method: :post, html: {:class => 'form-horizontal'} do |f|
= f.error_notification
%p#errorcontainer

.form-inputs
= f.input :name
= f.input :email, required: false
Expand Down
4 changes: 4 additions & 0 deletions app/views/home/feedback.html.haml
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
- content_for :javascript do
= javascript_include_tag 'validations'
%h1 Feedback form
.content
= simple_form_for @feedback, url: feedback_path, method: :post, html: {:class => 'form-horizontal'} do |f|
= f.error_notification
%p#errorcontainer

.form-inputs
= f.input :name
= f.input :email
Expand Down
2 changes: 2 additions & 0 deletions app/views/levels/_form.html.haml
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
- content_for :javascript do
= javascript_include_tag 'validations'
= simple_nested_form_for @level, html: {:class => 'form-horizontal'} do |f|
= f.error_notification
%p#errorcontainer
Expand Down
3 changes: 3 additions & 0 deletions app/views/topics/_form.html.haml
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
- content_for :javascript do
= javascript_include_tag 'validations'
= simple_nested_form_for [@level, @topic], html: {:class => 'form-horizontal'} do |f|
= @topic.errors.full_messages

- if !@topic.errors.empty?
%p#errorcontainer
.form-inputs
Expand Down
Empty file added app/views/topics/create.js.haml
Empty file.
2 changes: 2 additions & 0 deletions app/views/topics/new.html.haml
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
%h1.delta New topic for #{@level.level_name} level
.content
= render 'form'
- content_for :javascript do
= javascript_include_tag 'nested_form'
5 changes: 3 additions & 2 deletions app/views/users/_frmprofile.html.haml
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
- content_for :javascript do
= javascript_include_tag 'global'
= javascript_include_tag 'validations'

= stylesheet_link_tag 'calendar'
= simple_form_for @user, url: profile_path(@user), method: :post, html: {:class => 'form-horizontal'} do |u|
= u.error_notification
= u.simple_fields_for :profile do |p|
%p#profile

%p#errorcontainer
.form-inputs
= p.input :first_name
= p.input :last_name
Expand Down
Binary file not shown.

0 comments on commit 44d0da8

Please sign in to comment.