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

Thread: EditView and dropdown issues.

  1. #1
    spectheintro is offline Sugar Community Member
    Join Date
    May 2006
    Posts
    59

    Default EditView and dropdown issues.

    Does anyone know if it's possible for a dropdown to keep its original value when you're editing a record? For example, I have a custom module with two custom dropdowns. Every time I edit a record inside of that module, the dropdowns reset to their default values in the edit page, so if I click save, the record gets saved with the default dropdown values. It's going to be a big hassle to have people have to remember to re-adjust those dropdowns every time they edit a record. Is there any way to make those dropdowns retain their previous values by default when the record is edited? Thanks

  2. #2
    tj@estreet.com is offline Sugar Community Member
    Join Date
    Feb 2006
    Posts
    163

    Default Re: EditView and dropdown issues.

    I don't see any examples of dropdowns employed in any default Sugar EditView, and have had occasion in
    custom modules to forgo Sugar's dropdown conventions in favor of a hard coded <select> in the html.
    If you go that rout you MIGHT be able to set
    PHP Code:
    //

    if (isset($_REQUEST['custom_field'])) $xtpl->assign("CUSTOM_FIELD"$_REQUEST['custom_field']);

    // 
    in your EditView.php, AND smithing like
    Code:
    <select name="custom_field" {CUSTOM_FIELD}>
    	<option>Select</option>
    	<option value="1">1</option>
    	<option value="2">2</option>
    	<option value="3">3</option>
    	</select>
    in your EditView.html ????
    Last edited by tj@estreet.com; 2007-06-21 at 05:02 PM.

  3. #3
    spectheintro is offline Sugar Community Member
    Join Date
    May 2006
    Posts
    59

    Default Re: EditView and dropdown issues.

    A good example is the Salutations field in Contacts. If you choose Mr., it will stay Mr. unless you go back and manually change it yourself. With my dropdowns, every time you edit a record, they reset themselves. I'm going to examine the code around salutation and see if I can figure out what makes it different.

  4. #4
    tj@estreet.com is offline Sugar Community Member
    Join Date
    Feb 2006
    Posts
    163

    Default Re: EditView and dropdown issues.

    Okay, sure.
    I had to revert to OEM Sugar install to find it as we did away with the salutations
    in our production crm ages ago, but it looks pretty straigt forward provided:

    One of the option values for the dropdown in question is stored in a corrispoinding field in the corrisponding table FOR the current record ie (custom_table.custom_field WHERE custom_table.id = $focus->id )

    And you have something like
    PHP Code:
     //
    $xtpl->assign("CUSTOM_FIELD_OPTIONS"get_select_options_with_id($app_list_strings['custom_field_dom'], $focus->custom_field));
    // 
    in CutomModuel/EditView.php

    And something like
    PHP Code:
    //
    <select name='custom_field'>{CUSTOM_FIELD_OPTIONS}</select>// 
    in your CutomModuel/EditView.html

    but I could be wrong.

  5. #5
    spectheintro is offline Sugar Community Member
    Join Date
    May 2006
    Posts
    59

    Default Re: EditView and dropdown issues.

    Quote Originally Posted by tj@estreet.com
    Okay, sure.
    I had to revert to OEM Sugar install to find it as we did away with the salutations
    in our production crm ages ago, but it looks pretty straigt forward provided:

    One of the option values for the dropdown in question is stored in a corrispoinding field in the corrisponding table FOR the current record ie (custom_table.custom_field WHERE custom_table.id = $focus->id )

    And you have something like
    PHP Code:
     //
    $xtpl->assign("CUSTOM_FIELD_OPTIONS"get_select_options_with_id($app_list_strings['custom_field_dom'], $focus->custom_field));
    // 
    in CutomModuel/EditView.php

    And something like
    PHP Code:
    //
    <select name='custom_field'>{CUSTOM_FIELD_OPTIONS}</select>// 
    in your CutomModuel/EditView.html

    but I could be wrong.
    First, thank you for your responses--I really appreciate it.

    I do have that code in my EditView.php file already, but it hasn't made any difference. These dropdowns were created and placed using the Studio, so they're not entirely "custom" built.

    Any other ideas about what could make the entry not be retained? Would it help if I uploaded my EditView.php file?

  6. #6
    mapm's Avatar
    mapm is offline Sugar Community Member
    Join Date
    Aug 2006
    Location
    Portugal
    Posts
    239

    Default Re: EditView and dropdown issues.

    Before assign try to print the field something like:
    echo "Custom_field:".$focus->custom_field;
    Try to find if the field custom_field is being written to database
    you also can try to see if the field is in your custom module bean there shoud be some field inside it like $this->custom_field;

    Post some information about it here.

  7. #7
    spectheintro is offline Sugar Community Member
    Join Date
    May 2006
    Posts
    59

    Default Re: EditView and dropdown issues.

    Hmm, I actually made a new custom dropdown and it's not having the problem, which confuses the hell out of me...

    The dropdowns I have in there now were made using ModuleBuilder (I imported them as the final step) since the ultimate goal was to make a module I could drop in to a production box of SugarCRM. They didn't transition very well (I've had to do a lot of manual editing) and I am beginning to think this may be another example of them being broken.

    Does anyone know exactly where the code for custom dropdowns is stored? I can't find any evidence of my new dropdown in the EditView.php file, even though I created and added it via Studio. I want to take a look at the code studio generated to compare it side-by-side to the code I have for my imported dropdowns, to see what I'm missing. There's got to be a setting somewhere that's causing it to reset everytime, because clearly this isn't standard behavior.

  8. #8
    spectheintro is offline Sugar Community Member
    Join Date
    May 2006
    Posts
    59

    Default Re: EditView and dropdown issues.

    Ok, I figured it out.

    I don't know how this happened, but for some reason the following code was inserted into my EditView.php file:

    PHP Code:
    if (empty($_REQUEST['carrier'])) {
    $xtpl->assign("OPTIONS_CARRIER"get_select_options_with_id($app_list_strings['Carriers'], $app_list_strings['carrier_default_key']));
    }else{ 
    Once I commented out that if statement, everything worked properly. Thank you both for your efforts to help me!

  9. #9
    mapm's Avatar
    mapm is offline Sugar Community Member
    Join Date
    Aug 2006
    Location
    Portugal
    Posts
    239

    Default Re: EditView and dropdown issues.

    That if is there to ensure that for the first time you get there you dropdown will have the default value.
    If you take it the, dropdown for a new editview item, will allways have the first dropdown option element.
    So what I suggest to you is replace the if maybe for something like:

    PHP Code:
    if (empty($_REQUEST['custom_field']) && empty($focus->custom_field) {
    $xtpl->assign("CUSTOM_FIELD_OPTIONS"get_select_options_with_id($app_list_strings['custom_field_dom'], $app_list_strings['CUSTOM_FIELD_default_key']));
     } else {
    $xtpl->assign("CUSTOM_FIELD_OPTIONS"get_select_options_with_id($app_list_strings['custom_field_dom'], $focus->custom_field));
     } 
    so if $focus->custom_field isn't empty means that you are editing some information retrieved form database so the selected item should be the one whose value mathes $focus->custom_field.

    Hope it's right and helpful
    Last edited by mapm; 2007-06-22 at 04:34 AM.

  10. #10
    spectheintro is offline Sugar Community Member
    Join Date
    May 2006
    Posts
    59

    Default Re: EditView and dropdown issues.

    Quote Originally Posted by mapm
    That if is there to ensure that for the first time you get there you dropdown will have the default value.
    If you take it the, dropdown for a new editview item, will allways have the first dropdown option element.
    So what I suggest to you is replace the if maybe for something like:

    PHP Code:
    if (empty($_REQUEST['custom_field']) && empty($focus->custom_field) {
    $xtpl->assign("CUSTOM_FIELD_OPTIONS"get_select_options_with_id($app_list_strings['custom_field_dom'], $app_list_strings['CUSTOM_FIELD_default_key']));
     } else {
    $xtpl->assign("CUSTOM_FIELD_OPTIONS"get_select_options_with_id($app_list_strings['custom_field_dom'], $focus->custom_field));
     } 
    so if $focus->custom_field isn't empty means that you are editing some information retrieved form database so the selected item should be the one whose value mathes $focus->custom_field.

    Hope it's right and helpful
    Your code worked flawlessly--I just needed to add the && statement. I can't believe I didn't think to look there earlier.

    Thanks again for your patience!

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. Newbie: Default values in Dropdown
    By edvsw in forum Help
    Replies: 0
    Last Post: 2006-11-15, 09:15 AM
  2. Dropdown
    By cecilia in forum Developer Help
    Replies: 1
    Last Post: 2006-10-25, 03:11 PM
  3. Bug in Meetings Editview custom field
    By inmapi in forum Help
    Replies: 2
    Last Post: 2006-09-17, 03:26 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
  •