Jump to content

jimfog

Members
  • Posts

    1,803
  • Joined

  • Last visited

Posts posted by jimfog

  1. So far in my event handlers I never used the stopPropagation method to prevent bubbling.

    I just use event.preverntDefault to prevent the default behavior and that's it.

     

    The question is if it is really necessary to use it.

     

    In my case I have a form with fieldsets inside of it(with click event handlers at the various submit buttons).

     

    All of these have a parent element and the strange thing is that jquery attaches an event handler to it too(I cannot understand why jquery does that).

     

    So the bubbling ends up at the parent element.

     

    Thanks

  2. the index of method has a drawback. It returns the index of the member-if that is found of course.

    So, you have to know from before the possible index of the member you are looking.

     

    That index may vary. I would go the function that is depicted above since I only want a true/false and nothing else.

    It suits my needs better.

  3. I have made a for loop which examines the data object which is returned from the server with ajax.It contains a number of false/true depending on what the user submitted with the form...and after the various server-side checks have been made. there is a topic about it here:http://w3schools.invisionzone.com/index.php?showtopic=48736&hl=

     

    I am not posting on the above topic cause I am dealing with a different problem. I will not get into details...what was said there, I will just show you the code and move straight on the problem description:

     success:function(data){          var fields = ['address','city','municiplaity','url'];          var missing = [];            for (var i=0; i < fields.length; i++) {                     var f = fields[i];                     if (data[f] === false) {                          missing.push(f);                             }                        }          if (missing.length > 0) {                              $('#adrserror').text('You have to fill in: ' + missing.join(', '));                        if(contains(missing, "url")) {               $('#urlerror').text('You have not entered a correct URL);                    }               }

    The problem with the above code is that if URL is false it will get pushed to the missing array. this array though contains the other 3 "falses" too.These other 3 false(address,city,municiplaity...if of course the server-side checks return false) share a common attribute, They are false if the user has not completed the relevant(required fields) and as such...the message will be the same for them...meaning you have to fill in:...

     

    The above though does not apply for the URL, for which I have made a separate message as you see...

    The problem is URL false gets inevitable pushed to the missing array(if false) and the result is that the message that is displayed is also "You have to fill in:URL", something I do not want cause URL is not a required field.

     

     

  4. I am reading this tutorial here: http://coding.smashingmagazine.com/2013/10/21/challenging-css-best-practices-atomic-approach/

     

    In a section of the article called MARKUP(there are more than one sections named MARKUO), I am talking about the one below a smashing magazine tweet.

     

    In the section to which I am referring above it says

     

     

    We are using five classes, none of which are related to content:

    I cannot understand it. What about class Bfc Fz-s. Is in it related to content? Namely @thierrykoblentz 14 minutes ago

  5. Ok, I understood. I have never heard/seen though of an URL having a quote.

    Have you?

    And another thing. This is the pattern I found to use for the regular expression:https://raw.github.com/jzaefferer/jquery-validation/master/src/additional/url2.js

    After playing a while with it I found that it is very cumbersome to wotk with such code...when errors appear they are difficult to be found

    Maybe I should use the validate filter at all.

     

    WHat is your opinion?

  6. I found a regular expression to use.It is too long to show it...I do not think it matters anyway though.

    I have 1 question though. What is the reason for using quote inside the pattern...here is an example:

    da-f]{2})|[!$&'()*+

    PHP manual does not list quote as being a meta-character.

  7. So far I've used php filter for validating the url. I just noticed though that URLs like http://kkk pass validation...something I do not want.

    Do I have to resort to regular expression? And if yes...can you give me a help on that?

  8.  

    The text fields come from the English-speaking user?

    Τhe text comes from Greek user.That is why the error messages must be in Greek.

    But, in the server script the array keys are in English and these are what is returned from the server to the client with ajax.

    So there must be a match between the English array keys and the Greek error messages

     

    Meaning...when an array key is returned false from the server(after the checks have been made)the corresponding Greek message appears.

  9. If I wanted to check if a an array contains a specific member....'car' for example.

    What method should I use to do it? I looked at some methods in w3schools tutorial but I

    cannot find a method that can perform a specific task.

     

    The logic is that if a specific member is found in the array then do ...this.

  10. The use of remove instead of just recalling .text or .html to overwrite stuff you put in adrserror is just habit I'd get into. Remove() also looks for and deletes event handlers that were attached to the deleted elements. Though you didn't add any events in the current example, it a good habit to get into since events linking to elements that no longer exist can cause serious memory leaks.

    Yes, but the problem with remove() is that it deletes the element completely. That being said,if the checks are re-run there is no element in place to display the error message. The element returns in place if I hit the browser refresh button.

     

    Now,I want to mention a last thing about the loop...the fields array contains the items in English...I want though the displayed messages to be in Greek(my native labguage).

     

    What can I do?

    In other words what gets "pushed" in the missing array must be Greek.

     

    What could I do to achieve the above?

  11.  

    What about it?

    regrading the keyup event now...here is the code I am using now:

    $("#email").keyup(function()

    Should I pass an event object as an argument to the above?

    From what I have understood so far the answer should be yes.

     

    I am asking though, because there is not here any default behavior to be

    prevented...it is not a form submit button.

  12. I though that jquery could handle browser inconsistencies without resorting to the event object...obviously I was wrong.

     

    And something else...should this event object be used only when we want to prevent the default behavior of an event?

    What about a keyup event where the user starts typing something...actually I am talking about the case where a username is checked against

    the db.

  13. there is one last comment I want to add.

    I saw in the examples in stack overflow that in the function/event handler a parameter is passed and that is e...I am talking about this here:

    $('a').click(function (e) { 

    Do you think there is any problem if someone does not follow the above scheme? For example, this is the code I use:

    $('#savecontact').click(function() {   event.preventDefault(); 
  14. Recently I came across with this code in a tutorial found here http://net.tutsplus.com/tutorials/javascript-ajax/submit-a-form-without-page-refresh-using-jquery/?search_index=6:

    $.ajax({    type: "POST",    url: "bin/process.php",    data: dataString,    success: function() {      //display message back to user here    }  });  return false;

    I am trying to understand what return false is doing there.I think that the above ajax request is found in a click event handler...something

    not depicted in the tutorial.

    Do you think return false is needed there?

  15.  

    I'm using .append() instead of .text() so that I could display the messages separately and in tags (I also changed adrserror from span to div, and removed the following br tag).

    I am going to have a deeper look at your code,even for learning purposes.

     

    One question I have though is why you changed adrserror from being a span element to a div element?

×
×
  • Create New...