New Salsa Error Checking


/ Published in: jQuery
Save to your folder(s)

SO with the addition of Action 3 framework, we have discovered new Salsa form error checking.   The way Salsa used to do its error checking was to submit the page with the values it had.  WHen those values hit the processing page, that page would determine if required fields were missing.  If they were missing it would redirect to the form page and display a message that required fields were missing.\r\nNow with Action 3.0 the form validation happens on the page before it submits. \r\n\r\nHere you can see it reads the required fields into an array, loops thru the array looking for inputs with that name.  If it finds that the inputs have no value, it assigns a new class to the input, errorInput, which highlights the input with a red box.  \r\n\r\nWhat is also interesting is it seems to do the post inside this function as well.  I had noticed this page:\r\nhttp://act.truemajorityaction.org/p/salsa/web/common/public/content?content_item_KEY=50 flashed what seemed to be itself before the redirect.  I believe that it is due to the post function.


Copy this code and paste it in your HTML
  1. function submitForm(form) {
  2. //Check that any required fields are filled out
  3. var req=$(form).find("input[name='required']").val();
  4.  
  5. if (req){
  6. var hasRequired=true;
  7. req=req.split(",");
  8. for (var i=0; i<req.length; i++){
  9. if (!req[i]) continue;
  10. var field=$(form).find("select[name='"+req[i]+"'],input[name='"+req[i]+"']");
  11. //if there is no such field, continue on
  12. if (field.length==0) continue;
  13. var val=field.val();
  14. if (val==null || val.length==0){
  15. hasRequired=false;
  16. field.addClass("errorInput");
  17. }else{
  18. field.removeClass("errorInput");
  19. }
  20. }
  21. }
  22. if (hasRequired==false){
  23. $("#errorMessage").html("<span class='error'>Please fill out all required fields<br /> (did you remember to pick a candidate?)</span>");
  24. return false;
  25. }
  26.  
  27. $('#sending').show()
  28.  
  29. $.post('/salsa/api/action/processAction2.jsp', $(form).serializeArray(),
  30. function(data) {
  31. $("#mainForm").html(data);
  32. }
  33. );
  34. return false;
  35. }

URL: http://act.truemajorityaction.org/p/salsa/web/common/public/content?content_item_KEY=50

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.