Results 1 to 6 of 6

Thread: Validating Phone number

  1. #1
    lenz1979 is offline Sugar Community Member
    Join Date
    Jun 2009
    Posts
    68

    Default Validating Phone number

    Hi!

    i use Sugar CE 6.2.3 and wanted to change the phone Validation.

    in sugar_grp1.js a function isValidPhone exists but it seems that the type phone will not call this function.

    in the editview:

    addToValidate('EditView', 'phone_fax', 'phone', false,'Fax' );

    but it seems to ignore the type "phone".

    is this a bug or is there no real phone validation?

    adding the following code in the switch will help calling the isValidPhone:

    break;case'phone':if(!isValidPhone(trim(form[validate[formname][i][nameIndex]].value))){isError=true;add_error_style(formname,va lidate[formname][i][nameIndex],invalidTxt+" "+validate[formname][i][msgIndex]);}
    Last edited by lenz1979; 2012-01-09 at 02:19 PM.

  2. #2
    rafael.q.g@hotmail.com's Avatar
    rafael.q.g@hotmail.com is offline Sugar Community Member
    Join Date
    Jun 2011
    Location
    Florianópolis - Brazil
    Posts
    782

    Default Re: Validating Phone number

    I have two suggestions you could try:
    1. Add on extensions for your module some code like: $dictionary['module_name']['fields']['field_name']['required']=true;
    2. Write a logic hook to validate field's content.
    Rafael Queiroz Gonçalves
    Advanced OMG UML Certified Professional
    Sun Certified Enterprise Architect for the Java Platform
    Sun Certified Programmer for the Java 2 Platform
    IBM Certified Advanced Application Developer - Lotus Notes and Domino
    IBM Certified Application Developer - IBM WebSphere Portlet Factory
    Computer Science Mastering / UFSC - PPGCC

  3. #3
    anthony.watson is offline Sugar Community Member
    Join Date
    Jan 2011
    Posts
    14

    Default Re: Validating Phone number

    Which logic hook would you use? I don't know of any that trigger before submit (but before_submit would be a good name for it). The closest hook to that is before_save, and by that point, the UI is already being reloaded.

    Same goes for the controller.

    The only solution that comes to my mind is to write your own event listener script, include it via editviewdefs, and basically fake the validation by checking the contents (maybe on blur?) and if it returns false, fire whatever the validator would fire for false. Let me check....

    Code:
    if(!isValidPhone(document.getElementById("phone_home").value )) {
        isError = true;
        add_error_style("EditView", "phone_home", invalidTxt + " " + "Home Phone");
    }
    Let me know if that works. I only tested it from the javascript console, so I don't know if it will actually prevent the form from submitting, etc.

  4. #4
    rafael.q.g@hotmail.com's Avatar
    rafael.q.g@hotmail.com is offline Sugar Community Member
    Join Date
    Jun 2011
    Location
    Florianópolis - Brazil
    Posts
    782

    Default Re: Validating Phone number

    The logic hook you need is: "before_save".
    Rafael Queiroz Gonçalves
    Advanced OMG UML Certified Professional
    Sun Certified Enterprise Architect for the Java Platform
    Sun Certified Programmer for the Java 2 Platform
    IBM Certified Advanced Application Developer - Lotus Notes and Domino
    IBM Certified Application Developer - IBM WebSphere Portlet Factory
    Computer Science Mastering / UFSC - PPGCC

  5. #5
    anthony.watson is offline Sugar Community Member
    Join Date
    Jan 2011
    Posts
    14

    Default Re: Validating Phone number

    Before save is not the place to put a validator, I don't think, as the form is already submitted. You can't prevent the save from competing (without killing the entire thread).

  6. #6
    Angel's Avatar
    Angel is offline Sugar Community Member
    Join Date
    Jul 2005
    Location
    Los Angeles
    Posts
    4,813

    Default Re: Validating Phone number

    Agreed, a logic hook is not the place for this as it doesn't have a way to interact with the interface so as to alert the user that they've done something they shouldn't do or that the data is bad, etc.

    There are a couple of ways of applying validation, but if you want it to occur when the Save button is clicked, take a look at this thread, as it has a good example of what to do:

    http://www.sugarcrm.com/forums/f6/pr...om-code-33721/
    Regards,

    Angel Magaña
    Co-Author: Implementing SugarCRM 5.x (Packt Publishing -- Sept. 2010)
    Blog: http://cheleguanaco.blogspot.com.
    Twitter: @cheleguanaco.

    ________
    | Projects: |_____________________________________
    |
    | CandyWrapper (.NET Wrapper for SugarCRM SOAP API). Source now available on GitHub!
    | GoldMine to SugarCRM Express Conversion. Latest: 1.0.1.7 (Nov. 3, 2009)
    | CRM SkyDialer (Skype Integration). Latest: 1.0.2 (Feb. 17, 2010)
    | Round Robin Leads Assignment
    | Phone Number Formatter
    | CaseTwit (Twitter Integration)
    ______________________________________________

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Phone number format
    By godam in forum Help
    Replies: 5
    Last Post: 2010-03-26, 09:16 AM
  2. Phone Number Search Help!
    By rfenn in forum General Discussion
    Replies: 5
    Last Post: 2009-02-21, 04:29 PM
  3. Add link on a phone number
    By Orbiplanax in forum Developer Help
    Replies: 5
    Last Post: 2007-11-29, 09:26 AM
  4. Fix for the Phone Number Search bug
    By kbrill in forum Downloads
    Replies: 7
    Last Post: 2007-06-27, 05:20 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •