Results 1 to 9 of 9
Like Tree3Likes
  • 1 Post By rafael.q.g@hotmail.com
  • 1 Post By rafael.q.g@hotmail.com
  • 1 Post By rafael.q.g@hotmail.com

Thread: trying to validate input

  1. #1
    danwguy is offline Junior Member
    Join Date
    Jun 2011
    Posts
    3

    Default trying to validate input

    I set up a very quick easy validation using javascript onblur event to pop up an alert message and focus on the field that needs to be fixed, I just added a 'javascript' tag in the detailview.php file. What I would like to do though is instead of having an alert pop up I woul dlike it to just say the message next to the field that is wrong and focus on that field. I know there are a ton of jquery libraries that can do that, but I am pretty new at sugarcrm and not sure how to go about implimenting that into it. Any help would be greatly appreciated. Thank you.

  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: trying to validate input

    You have to edit your detail/edit view files to adjust the code for the fields you want to validate. For each field you want to validade, you can add a custoCode atribute, that has to render the field, and also has to add a div at its side. Then your javascript function instead of alert on screen, could set the message into this div, assign the validation message to the innerHTML div attribute.

    Exemple of customCode:
    PHP Code:
    'customCode' => '<input type="text" name="field_name"   id="field_name" value="$fields->field_name->value"> <div id="field_name_validation_message"> </div> ' 
    Exemple of valitation messahe display:
    HTML Code:
    document.getElementById("field_name_validation_message").innerHTML="your_message";
    dkinzer likes this.
    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
    danwguy is offline Junior Member
    Join Date
    Jun 2011
    Posts
    3

    Default Re: trying to validate input

    So far so good, now I just need to add the javascript include in the <head> tags. I have tried going into the editviewdefs.php and adding"
    'includes' => array(
    0 =>
    array(
    'file' => 'custom/modules/CT221_SEP_test/livevalidation_standalone.js',
    ),
    1 =>
    array(
    'file' => 'custom/modules/CT221_SEP_test/validate.js',
    ),
    ),
    "
    but it doesn't include those two files in the page anywhere. Any advice on getting those two files into the <head></head> tags? please. Thank you.

    Also when I use that value="$fields->google_account_value" it literally puts that exact text into the input box. how would I get the value that's supposed to be there there? Thank you again for all your help
    Last edited by danwguy; 2011-06-24 at 07:29 PM.

  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: trying to validate input

    You can add the external javascript files to your application with this code:
    PHP Code:
    [....]
    'EditView' =>
                array(
                    
    'templateMeta' =>
                    array(
                        
    'includes' =>
                            array (
                            
    =>
                            array (
                                
    'file' => 'my_file_1.js',
                            ),
                            
    =>
                            array (
                                
    'file' => 'my_file_2.js',
                            ),
                            ),
    [...] 
    dkinzer likes this.
    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
    dkinzer's Avatar
    dkinzer is offline Sugar Community Member
    Join Date
    Sep 2011
    Posts
    67

    Default Re: trying to validate input

    Rafael, this was very useful. Thanks.

    I can even add javascript via a URL call, like:

    PHP Code:
          'includes' => 
          array (
            
    => 
            array (
              
    'file' => 'http://ajax.googleapis.com/ajax/libs/jquery/1.6.4/jquery.min.js',
            ), 
    I have two questions:

    Where is the best place to override if I want to include custom javascript on every page that has a form?

    Also, I'm wondering what happens to these files if I make a change in Studio. Does my change get overwritten?

    Best regards,

    David

  6. #6
    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: trying to validate input

    The java script files included using the 'includes' are not overwritten by changes done on studio, this informations are keeped.

    If you want to add a javascript file in all pages, I don't know any safe upgrade way to do it, but you can change the file include/MVC/view/SugarView.php adding in some function as displayFooter, the HTML code to include your javascript file (<script src="path"></script>).
    dkinzer likes this.
    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

  7. #7
    dkinzer's Avatar
    dkinzer is offline Sugar Community Member
    Join Date
    Sep 2011
    Posts
    67

    Default Re: trying to validate input

    Thanks again,

    David

  8. #8
    dkinzer's Avatar
    dkinzer is offline Sugar Community Member
    Join Date
    Sep 2011
    Posts
    67

    Default Re: trying to validate input

    It's a pretty simple matter to override that onclick event with jQuery as well:

    Code:
     $(':input#SAVE_FOOTER').attr('onClick', 'return false;');$
    Clearly this example would only stop the form from submitting, but you get the picture.

  9. #9
    dkinzer's Avatar
    dkinzer is offline Sugar Community Member
    Join Date
    Sep 2011
    Posts
    67

    Default Re: trying to validate input

    Ultimately the above technique never really worked for me, because even though my custom_check_form would be called, that only happens if the user clicks on the button. If the user just hits ENTER (char=13) then using the above technique doesn't work.

    What worked for me was to override the Sugar check_form with:

    Code:
      // Override SUGAR check_form function.$
      sugar_check_form = check_form;$
      check_form = function(form) {$
        return (sugar_check_form(form) && custom_check_form());~~$
      }$

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. How to validate fields like: field_name[]
    By jasv in forum Developer Help
    Replies: 2
    Last Post: 2010-08-10, 04:59 PM
  2. How to Validate Import Data's!
    By pixturema in forum Developer Help
    Replies: 2
    Last Post: 2010-06-01, 08:18 AM
  3. Web to Lead Form does not validate
    By kenlyle in forum Help
    Replies: 7
    Last Post: 2008-07-17, 09:11 PM
  4. License can not be validate
    By etasoftware in forum Installation and Upgrade Help
    Replies: 1
    Last Post: 2008-06-29, 03:20 PM
  5. Releases and Version plus validate ip
    By kasolg in forum Help
    Replies: 0
    Last Post: 2007-02-14, 07:53 AM

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
  •