Results 1 to 5 of 5

Thread: Entries verification in custom modules

  1. #1
    NairWick is offline Sugar Community Member
    Join Date
    May 2006
    Posts
    62

    Question Entries verification in custom modules

    I've recently been using the "Songs" tutorial to develop my own modules. It works quite well but I still have a problem. Considering I am using the Songs module, when i add a new one and forget to enter the title, the request just fails, the datas aren't checked to inform the user of a potential mistake before being sent.
    I've been looking around and it seems I'd have to add several files and modify much code. Aren't there simply a few code lines I can add somewhere ?


    Thx for your answers !

  2. #2
    julian's Avatar
    julian is offline Sugar Team Member
    Join Date
    Sep 2004
    Posts
    1,639

    Default Re: Entries verification in custom modules

    Hello NairWick,

    Marking a field required in vardefs.php for the particular module (i.e. ./modules/Songs/vardefs.php) should trigger validation on the client side. For an example, look in ./modules/Accounts/vardefs.php:

    PHP Code:
    'deleted' => 
      array (
        
    'name' => 'deleted',
        
    'vname' => 'LBL_DELETED',
        
    'type' => 'bool',
        
    'required' => true,
        
    'reportable'=>false,
        
    'default' => '0'
      
    ), 
    This marks the 'deleted' field as required for Accounts. You may need to run the "Rebuild Relationships" utility after saving vardefs.php, found in the Admin section under "Repair."
    Julian Ostrow
    Systems and Applications Engineer
    SugarCRM Inc.

  3. #3
    NairWick is offline Sugar Community Member
    Join Date
    May 2006
    Posts
    62

    Default Re: Entries verification in custom modules

    I am not sure the problem is there as the required velue is well entered.

    I mean, still in the Songs example, we have
    PHP Code:
    'title' => array(
                
    'name' => 'title',
                
    'vname' => 'LBL_TITLE',
                
    'required' => true,
                
    'type' => 'varchar',
                
    'len' => 255,
            ), 
    But when you use the mudule without modifications, the output when you ommit the title for a new entry is :
    PHP Code:
    NoticeUndefined indexisDuplicate in F:webdevSugarSuite-Full-4.2.0amodulesSongsSave.php on line 38
    Query Failed
    :INSERT into songs set id='c08abe71-0f25-bc8c-9d45-4463603819e4'date_entered='2006-05-11 16:05:29'created_by='1'date_modified='2006-05-11 16:05:29'modified_user_id='1'deleted='0'title=nulllength='0'description=nullbitrate=nullexplicit='0'genre=nullformat=null::MySQL error 1048Column 'title' cannot be null 
    So i guess the problem is not in vardefs.php but somewhere in how the Forms.php is made or called.

  4. #4
    julian's Avatar
    julian is offline Sugar Team Member
    Join Date
    Sep 2004
    Posts
    1,639

    Default Re: Entries verification in custom modules

    Hello NairWick,

    A couple problems exist there. Since no title is being entered, a blank string ("") is the value of that field. The SugarBean translates that to NULL before inserting it into the database, and the title column is marked as NOT NULL (will not accept NULL values). Since the field should be required, we can leave that part as is, but need to enforce the requirement on the client-side.

    Try making a JavaScript call to:

    Code:
    addToValidate(formname, name, type,required, msg)
    For example:

    Code:
    <script>addToValidate('test','time', 'time', false, 'TIME');</script>
    Echo a call like this somewhere where it will appear on the EditView screen (maybe even in ./modules/Songs/EditView.html) and see how it works.
    Julian Ostrow
    Systems and Applications Engineer
    SugarCRM Inc.

  5. #5
    NairWick is offline Sugar Community Member
    Join Date
    May 2006
    Posts
    62

    Thumbs up Re: Entries verification in custom modules

    Thx Julian, it all works fine now !

    In fact ,i had forgotten to call the javascript functions to check the form. When i saw that in other modules there were some called, i thought you got it right !

    Thanks again, i can go further now. Hard to be a beginned in sugar crm

Thread Information

Users Browsing this Thread

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

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
  •