Page 1 of 2 12 LastLast
Results 1 to 10 of 16

Thread: Custom Javascript onchange

  1. #1
    chrislynch8's Avatar
    chrislynch8 is offline Sugar Community Member
    Join Date
    Oct 2007
    Location
    Cork, Ireland
    Posts
    747

    Default Custom Javascript onchange

    Hi,

    I have custom javascript function that I am calling in the EditView of a module. I have added added the required lines of cose to the editviewdefs.php file.

    What can I put into the javascript to see if it is actually running when I change a field - also the field I am changing is a date field.

    Rgds
    Chris
    Linkedin Profile:Chris Lynch

    FDC IT Solutions
    FDC House
    Wellington Road
    Cork
    Ireland

  2. #2
    mikesolomon is offline Sugar Community Member
    Join Date
    Feb 2008
    Location
    UK
    Posts
    1,467

    Default Re: Custom Javascript onchange

    Quote Originally Posted by chrislynch8 View Post
    Hi,

    I have custom javascript function that I am calling in the EditView of a module. I have added added the required lines of cose to the editviewdefs.php file.

    What can I put into the javascript to see if it is actually running when I change a field - also the field I am changing is a date field.

    Rgds
    Chris
    Chris

    put in an alert

    i.e alert('this is working')

    that will popup a message
    Mike Solomon
    Development Manager
    Ivy Ltd
    www.ivy.ltd.uk]www.ivy.ltd.uk

    php version 5.2.6
    MySql 5.1.59

  3. #3
    chrislynch8's Avatar
    chrislynch8 is offline Sugar Community Member
    Join Date
    Oct 2007
    Location
    Cork, Ireland
    Posts
    747

    Default Re: Custom Javascript onchange

    Thats what I though.

    I've commented out all code and added alert("Got here"); and nothing.

    Rgds
    Chris
    Linkedin Profile:Chris Lynch

    FDC IT Solutions
    FDC House
    Wellington Road
    Cork
    Ireland

  4. #4
    mikesolomon is offline Sugar Community Member
    Join Date
    Feb 2008
    Location
    UK
    Posts
    1,467

    Default Re: Custom Javascript onchange

    Quote Originally Posted by chrislynch8 View Post
    Thats what I though.

    I've commented out all code and added alert("Got here"); and nothing.

    Rgds
    Chris
    How have you added it to editviewdefs?
    Mike Solomon
    Development Manager
    Ivy Ltd
    www.ivy.ltd.uk]www.ivy.ltd.uk

    php version 5.2.6
    MySql 5.1.59

  5. #5
    chrislynch8's Avatar
    chrislynch8 is offline Sugar Community Member
    Join Date
    Oct 2007
    Location
    Cork, Ireland
    Posts
    747

    Default Re: Custom Javascript onchange

    In my editviewdefs.php i have the following in the templateMeta array after the widths array

    PHP Code:
    'includes' =>
    array(
    =>
    array(
    'file' => 'modules/FDC_Aspire/FDC_Aspire.js',
            ),
    ), 
    Then in the field I want it to trigger on I added the following

    PHP Code:
    'displayParams' => array( 'javascript' =>'onchange="initData();"';,), 
    Then in the FDC_Aspire.js I have the

    function initData(){
    alert("Got Here");
    }

    Then when I change the date in the Module nothing happens

    Rgds
    Chris
    Linkedin Profile:Chris Lynch

    FDC IT Solutions
    FDC House
    Wellington Road
    Cork
    Ireland

  6. #6
    mikesolomon is offline Sugar Community Member
    Join Date
    Feb 2008
    Location
    UK
    Posts
    1,467

    Default Re: Custom Javascript onchange

    Quote Originally Posted by chrislynch8 View Post
    In my editviewdefs.php i have the following in the templateMeta array after the widths array

    PHP Code:
    'includes' =>
    array(
    =>
    array(
    'file' => 'modules/FDC_Aspire/FDC_Aspire.js',
            ),
    ), 
    Then in the field I want it to trigger on I added the following

    PHP Code:
    'displayParams' => array( 'javascript' =>'onchange="initData();"';,), 
    Then in the FDC_Aspire.js I have the

    function initData(){
    alert("Got Here");
    }

    Then when I change the date in the Module nothing happens

    Rgds
    Chris
    your problem is that 'displayParams' => array( 'javascript' =>'onchange="initData();"';,), will not work for a date field

    The easiest (but not upgrade safe way to fix it is to edit

    include/SugarFields/Fields/Datetime/EditView.tpl

    edit the input line to read <input autocomplete="off" type="text" name="{{sugarvar key='name'}}" id="{{sugarvar key='name'}}" value="{$date_value}" title='{{$vardef.help}}' {{$displayParams.field}} size="11" maxlength="10" tabindex="{{$tabindex}}" {{if isset($displayParams.javascript)}}{{$displayParams .javascript}} {{/if}}>

    the upgrade safe way to do it is to copy the Datetime field to a new field Datetime_js

    then edit as above

    Then in EditViewdefs add the line 'type' => 'Datetime_js'

    That should fix it
    Mike Solomon
    Development Manager
    Ivy Ltd
    www.ivy.ltd.uk]www.ivy.ltd.uk

    php version 5.2.6
    MySql 5.1.59

  7. #7
    chrislynch8's Avatar
    chrislynch8 is offline Sugar Community Member
    Join Date
    Oct 2007
    Location
    Cork, Ireland
    Posts
    747

    Default Re: Custom Javascript onchange

    I tried the non upgrade safe method it still doesn't work. When press the icon and select the new date I have to then press the X to close the Date picker but I still do not receive the alert.

    I'm am not great at JavaScript yet to even try the attempt the safer version.

    Rgds
    Chris
    Linkedin Profile:Chris Lynch

    FDC IT Solutions
    FDC House
    Wellington Road
    Cork
    Ireland

  8. #8
    mikesolomon is offline Sugar Community Member
    Join Date
    Feb 2008
    Location
    UK
    Posts
    1,467

    Default Re: Custom Javascript onchange

    Quote Originally Posted by chrislynch8 View Post
    I tried the non upgrade safe method it still doesn't work. When press the icon and select the new date I have to then press the X to close the Date picker but I still do not receive the alert.

    I'm am not great at JavaScript yet to even try the attempt the safer version.

    Rgds
    Chris
    Chris

    can you put up the code you are using in the editviewdefs here

    also the vardefs where the field is defined
    Mike Solomon
    Development Manager
    Ivy Ltd
    www.ivy.ltd.uk]www.ivy.ltd.uk

    php version 5.2.6
    MySql 5.1.59

  9. #9
    chrislynch8's Avatar
    chrislynch8 is offline Sugar Community Member
    Join Date
    Oct 2007
    Location
    Cork, Ireland
    Posts
    747

    Default Re: Custom Javascript onchange

    Hi Mike,

    Here are the two files attached.

    Rgds
    Chris
    Attached Files Attached Files
    Linkedin Profile:Chris Lynch

    FDC IT Solutions
    FDC House
    Wellington Road
    Cork
    Ireland

  10. #10
    mikesolomon is offline Sugar Community Member
    Join Date
    Feb 2008
    Location
    UK
    Posts
    1,467

    Default Re: Custom Javascript onchange

    Quote Originally Posted by chrislynch8 View Post
    Hi Mike,

    Here are the two files attached.

    Rgds
    Chris
    could you try this in editviewdefs

    array (
    'name' => 'fdc_date_online_one',
    'label' => 'LBL_FDC_DATE_ONLINE_ONE',
    'type' => 'datetime',
    'displayParams'=>array('javascript' => 'onchange="initData();"'),
    ),
    Mike Solomon
    Development Manager
    Ivy Ltd
    www.ivy.ltd.uk]www.ivy.ltd.uk

    php version 5.2.6
    MySql 5.1.59

Page 1 of 2 12 LastLast

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. Javascript onchange
    By danrweki in forum Developer Help
    Replies: 13
    Last Post: 2012-05-03, 09:52 AM
  2. Javascript - Onchange
    By ff76 in forum Developer Help
    Replies: 5
    Last Post: 2010-11-05, 10:28 PM
  3. javascript function onchange not working in Multiselect
    By sriramm in forum General Discussion
    Replies: 2
    Last Post: 2010-04-09, 09:58 AM
  4. onchange event and javascript function in country drop down
    By sriramm in forum General Discussion
    Replies: 0
    Last Post: 2009-09-04, 03:45 AM
  5. Javascript onchange not working
    By danrweki in forum Help
    Replies: 0
    Last Post: 2008-07-31, 12:24 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
  •