From b45ed915dc41b5d0e286bfc2517fb776eec4dc80 Mon Sep 17 00:00:00 2001 From: jpl Date: Wed, 28 Jun 2017 17:45:46 +0200 Subject: Refs #3862: adding validation on ITL form --- .../javascripts/routing_constraint_zones.coffee | 47 +++++++++++++--------- 1 file changed, 29 insertions(+), 18 deletions(-) (limited to 'app/assets/javascripts') diff --git a/app/assets/javascripts/routing_constraint_zones.coffee b/app/assets/javascripts/routing_constraint_zones.coffee index ceb9fb218..8721dfb38 100644 --- a/app/assets/javascripts/routing_constraint_zones.coffee +++ b/app/assets/javascripts/routing_constraint_zones.coffee @@ -30,29 +30,40 @@ $('#ITL_stoppoints').find('.nested-fields').remove() $('#ITL_stoppoints').find('.nested-head').after(html) - # VALIDATION - selection = [] - $('#ITL_stoppoints').on 'click', "input[type='checkbox']", (e) -> - v = $(e.target).val() + # VALIDATION + selection = [] - if ( $.inArray(v, selection) != -1 ) - selection.splice(selection.indexOf(v), 1) - else - selection.push(v) + totalItems = collection.length - alertMsg = "
-

Un ITL doit comporter au moins deux arrêts

-
" + $('#ITL_stoppoints').on 'click', "input[type='checkbox']", (e) -> + v = $(e.target).val() - $(document).on 'click', "input[type='submit']", (e)-> - inputName = $('#routing_constraint_zone_name').val() + if ( $.inArray(v, selection) != -1 ) + selection.splice(selection.indexOf(v), 1) + else + selection.push(v) - $('.alert-danger').remove() + alertMsg1 = "
+

Un ITL doit comporter au moins deux arrêts

+
" + alertMsg2 = "
+

Un ITL ne peut recouvrir tous les arrêts d'un itinéraire

+
" - if ( selection.length < 2 && inputName != "") - e.preventDefault() - $('#routing_constraint_zone_name').closest('.form-group').removeClass('has-error').find('.help-block').remove() - $('#ITL_stoppoints').prepend(alertMsg) + $(document).on 'click', "input[type='submit']", (e)-> + inputName = $('#routing_constraint_zone_name').val() + + $('.alert-danger').remove() + + if ( selection.length < 2 && inputName != "" ) + e.preventDefault() + $('#routing_constraint_zone_name').closest('.form-group').removeClass('has-error').find('.help-block').remove() + $('#ITL_stoppoints').prepend(alertMsg1) + + if ( selection.length == totalItems && inputName != "" ) + e.preventDefault() + $('#routing_constraint_zone_name').closest('.form-group').removeClass('has-error').find('.help-block').remove() + $('#ITL_stoppoints').prepend(alertMsg2) $ -> ITL_stoppoints() -- cgit v1.2.3