FWIW, I just found why it didn't work earlier. I was editing the wrong .html file. Meat Head. Blame it on Friday afternoon...
-Jim On Friday, November 16, 2012 4:06:33 PM UTC-6, Jim S wrote: > > FYI - I got it working by putting the JS in layout.html within my > $(document).ready(function() code. But, now it is working ok for adding a > new record, but doesn't display the value in the second SELECT on edit. > That one doesn't work with suggest_widget on the first field either. Even > if I get it working it seems too delicate. I'm going to find another way > to handle this one. > > But, thanks for your JS help, I do appreciate it. > > -Jim > > > On Friday, November 16, 2012 3:54:37 PM UTC-6, Richard wrote: >> >> You too! >> >> Bye! >> >> Richard >> >> On Fri, Nov 16, 2012 at 4:47 PM, Jim S <[email protected]> wrote: >> >>> Thanks Richard, didn't think of changing the background to help me >>> diagnose. Will work on it more this afternoon but pick it up again on >>> Monday. Have a good weekend! >>> >>> -Jim >>> >>> On Friday, November 16, 2012 3:44:16 PM UTC-6, Richard wrote: >>> >>>> I have to go... Sorry... >>>> >>>> It surely a selector that not catch what it suppose to... >>>> >>>> My form use formestyle=divs that maybe affect somehow... >>>> >>>> Richard >>>> >>>> On Fri, Nov 16, 2012 at 4:40 PM, Richard Vézina >>>> <[email protected]>wrote: >>>> >>>>> Jim, >>>>> >>>>> You can put the jQuery directly in html create/update form like this : >>>>> <script> >>>>> $("select[name=FIRSTFIELDNAME]").change(function() { >>>>> var val = $(this).children(":selected").attr("value"); >>>>> $(this).trigger($(this).attr("id") + "__selected", [val]); >>>>> }); >>>>> </script> >>>>> >>>>> To make sure you selector are good you can set a background color like >>>>> this : >>>>> >>>>> $(this).children(":selected").css('background-color','red'); >>>>> >>>>> Richard >>>>> >>>>> >>>>> On Fri, Nov 16, 2012 at 4:30 PM, Jim S <[email protected]> wrote: >>>>> >>>>>> Well, I can get it to work with smartgrid if I use a suggest_widget >>>>>> for the first field. But, I'm trying to make my second SELECT element >>>>>> reload its options based on the option selected in the first SELECT >>>>>> element. I was trying to follow the JS that you posted earlier, but I >>>>>> can't get it to trigger the reload of the second SELECT element. >>>>>> >>>>>> With the smartgrid, the html element IDs are a bit different, but >>>>>> I've accommodated for that with the version I have working with the >>>>>> suggest_widget. >>>>>> >>>>>> I'm looking for a way to debug this thing and see what is actually >>>>>> going on. I can't say I'm a strong javascript'er but my understanding >>>>>> is >>>>>> that this code should end up somewhere on the 'view page source' html, >>>>>> and >>>>>> it isn't. Would I be able to return it to the script and have it >>>>>> execute >>>>>> if I use the response.js variable? Seems like it never gets executed. >>>>>> >>>>>> -Jim >>>>>> >>>>>> On Friday, November 16, 2012 3:19:40 PM UTC-6, Richard wrote: >>>>>> >>>>>>> It may be related to smartgrid... >>>>>>> >>>>>>> Have you try with a straight sqlform?? >>>>>>> >>>>>>> Richard >>>>>>> >>>>>>> >>>>>>> On Fri, Nov 16, 2012 at 3:31 PM, Jim S <[email protected]> wrote: >>>>>>> >>>>>>>> Richard - I've been trying to get this working but am not having >>>>>>>> any luck. I have the lazy_options_widget working with the first field >>>>>>>> being a suggest_widget, but am trying to implement with your >>>>>>>> suggestion >>>>>>>> above using a SELECT element as the first field, but it isn't working. >>>>>>>> I'm >>>>>>>> using this in an edit for generated by a smartgrid and am using the >>>>>>>> following for the FIRSTFIELDNAME as you have it above. >>>>>>>> >>>>>>>> benefit_benefitProgramId >>>>>>>> >>>>>>>> This is the ID associated with the first field when I look at the >>>>>>>> HTML that is generated. I think I'm following along with the >>>>>>>> javascript >>>>>>>> ok, but don't understand why my code isn't working. >>>>>>>> >>>>>>>> Any tips on what to look for? Did you actually have this working >>>>>>>> in a sample? >>>>>>>> >>>>>>>> Any help would be appreciated. >>>>>>>> >>>>>>>> -Jim >>>>>>>> >>>>>>>> On Wednesday, August 29, 2012 9:25:07 AM UTC-5, Richard wrote: >>>>>>>> >>>>>>>>> Here the code for use a regular drop down and avoid use of >>>>>>>>> autocomplete plugin dependency. >>>>>>>>> >>>>>>>>> In controller : >>>>>>>>> conditional_field_trigger_selected_event_js = >>>>>>>>> '$("select[name=FIRSTFIELDNAME]").change(function() {var val = >>>>>>>>> $(this).children(":selected").attr("value");$(this).trigger($(this).attr("id") >>>>>>>>> >>>>>>>>> + "__selected", [val]);});' >>>>>>>>> >>>>>>>>> In view : >>>>>>>>> <script type="text/javascript"> >>>>>>>>> {{=XML(conditional_field_trigger_selected_event_js)}} >>>>>>>>> </script> >>>>>>>>> >>>>>>>>> Richard >>>>>>>>> >>>>>>>>> On Wed, Aug 29, 2012 at 10:21 AM, Anthony <[email protected]>wrote: >>>>>>>>> >>>>>>>>>> See >>>>>>>>>> http://stackoverflow.com/questions/8146260/best-practice-for-populating-dropdown-based-on-other-dropdown-selection-in-web2p/8152910#8152910 >>>>>>>>>> for >>>>>>>>>> links to some other related recipes. >>>>>>>>>> >>>>>>>>>> Anthony >>>>>>>>>> >>>>>>>>>> >>>>>>>>>> On Wednesday, August 29, 2012 3:04:10 AM UTC-4, lyn2py wrote: >>>>>>>>>>> >>>>>>>>>>> Thank you Anthony and Richard, I have tried to use IS_IN_DB in >>>>>>>>>>> the form of return IS_IN_DB(...) but it doesn't work. >>>>>>>>>>> >>>>>>>>>>> The reason why I am looking for this function is because I am >>>>>>>>>>> trying to load the options or a second field, based on what is >>>>>>>>>>> chosen in >>>>>>>>>>> the first field. Both are SELECTs. >>>>>>>>>>> >>>>>>>>>>> Like this example here: >>>>>>>>>>> http://dev.s-cubism.com/plugin_lazy_options_widget >>>>>>>>>>> but the first field is a select instead of autocomplete. >>>>>>>>>>> >>>>>>>>>>> I am unable to find a function that will return a SELECT field >>>>>>>>>>> (based on the chosen rows) for the ajax success function. >>>>>>>>>>> >>>>>>>>>>> On Wednesday, August 29, 2012 12:50:13 AM UTC+8, Anthony wrote: >>>>>>>>>>>> >>>>>>>>>>>> Yes. By default, a reference field gets a validator like this: >>>>>>>>>>>> IS_IN_DB(db, db.sometable._id, db.sometable._format). However, the >>>>>>>>>>>> IS_IN_DB() validator can take a Set object as the first argument >>>>>>>>>>>> instead of >>>>>>>>>>>> db, and the list will be based on the records defined by that Set. >>>>>>>>>>>> In that >>>>>>>>>>>> case, you'll have to explicitly define the validator: >>>>>>>>>>>> >>>>>>>>>>>> requires=IS_IN_DB(db([your query]), db.sometable.id, db. >>>>>>>>>>>> sometable._format) >>>>>>>>>>>> >>>>>>>>>>>> Note, when you define your own validator, you also lose the >>>>>>>>>>>> automatic "represent" attribute for the reference field, so you >>>>>>>>>>>> might want >>>>>>>>>>>> to set your own: >>>>>>>>>>>> >>>>>>>>>>>> represent=db.sometable._format >>>>>>>>>>>> >>>>>>>>>>>> Anthony >>>>>>>>>>>> >>>>>>>>>>>> On Tuesday, August 28, 2012 12:28:10 PM UTC-4, lyn2py wrote: >>>>>>>>>>>>> >>>>>>>>>>>>> Hello experts, >>>>>>>>>>>>> >>>>>>>>>>>>> Generally, when we do a SQLFORM, the 'reference table' fields >>>>>>>>>>>>> automatically gets *all* the available options for choosing as a >>>>>>>>>>>>> dropdown >>>>>>>>>>>>> menu. >>>>>>>>>>>>> >>>>>>>>>>>>> However, I would like to get a filtered list instead of *all* >>>>>>>>>>>>> of the items. Is there an available function I can use to achieve >>>>>>>>>>>>> a >>>>>>>>>>>>> filtered list for choosing in the dropdown menu? >>>>>>>>>>>>> >>>>>>>>>>>>> Another way to look at this is: >>>>>>>>>>>>> I would like to generate a SELECT/OPTIONS html using a >>>>>>>>>>>>> specific query, i.e. it uses the retrieved Rows to generate the >>>>>>>>>>>>> HTML. I >>>>>>>>>>>>> wonder if there is a function in web2py for doing this. >>>>>>>>>>>>> >>>>>>>>>>>>> I hope my question is understood. Thank you. >>>>>>>>>>>>> >>>>>>>>>>>>> >>>>>>>>>>>>> PS. If there isn't an available function, I appreciate any >>>>>>>>>>>>> tips or pointers how I can make this work. Thanks! >>>>>>>>>>>>> >>>>>>>>>>>> -- >>>>>>>>>> >>>>>>>>>> >>>>>>>>>> >>>>>>>>>> >>>>>>>>> >>>>>>>>> -- >>>>>>>> >>>>>>>> >>>>>>>> >>>>>>>> >>>>>>> >>>>>>> -- >>>>>> >>>>>> >>>>>> >>>>>> >>>>> >>>>> >>>> -- >>> >>> >>> >>> >> >> --

