6 Replies Latest reply on Feb 7, 2008 2:37 PM by (Tony_Galfano)

    Requery Drop Down after new record added

      Hi,

      I have a form built with ADDT. There is a dropdown box tied to the buyers table (ID, Name) and a button to add new buyers. The buyers table has full contact info in it so I can't use the editable drop down. I need to be able to requery the drop down box after the user clicks the add buyer button, which opens a window with the add buyer form, so that it checks the table again and shows the new buyer in the drop down list.

      At the moment I have it all working except that when the user adds a new buyer they have to refresh the page, losing any data already entered, in order to see the newly entered data in the drop down. Is there a way to requery the drop down after a new record has been entered or when the user clicks the submit button of the add buyer form? Or, maybe requery when the user clicks on the control again after entering the new buyer?

      Any help is much appreciated,

      Tony
        • 1. Re: Requery Drop Down after new record added
          Günter Schenk Level 4
          Hi Toni,

          that´s technically not possible without reloading the main form -- two possible workarounds:

          a) add a note to the "add buyer" button telling folks they´ll have to add a new buyer before entering any other data, what´s of course a pretty inconvenient solution. However, just in case you´re opening that extra window using a javascript popup, you could add a "window.opener.reload()" link to the corresponding "redirect after insert" page which will refresh the parent window

          b) rather add a link to the Dynamic List, place it above the list, have it point to the "add buyers" Insert Record form and also make it open in a new window -- IMO this is the better solution, as the procedures are clearly separated from each other.

          Cheers,
          Günter Schenk
          Adobe Community Expert, Dreamweaver
          • 2. Re: Requery Drop Down after new record added
            Level 1
            Hi Gunter,

            Thanks for the quick reply. The problem is that there are 4 such drop downs in the page and a good percentage of the time they'll need to enter new data for at least one of them. There are also too many controls with data by that time to lose.

            I was wondering whether or not there are any ajax components that would work better than the standard drop downs? If the control is requerying in the background it would pick up any new values in the database. Do any of the spry controls fit the bill? Or is there a way to use the Spry Utilities extension to requery the table on some action? Seems like someone would have invented a control that requeries tables via javascript.

            Any ideas are much appreciated. Thanks for the help. If you can think of any other tools that could replace linked drop down boxes, or extensions that would requery the combos please let me know. I'd happily pay to get it!

            Thanks again.

            Tony
            • 3. Re: Requery Drop Down after new record added
              Günter Schenk Level 4
              Hi Tony,

              ----
              I was wondering whether or not there are any ajax components that would work better than the standard drop downs?
              ----

              ADDT´s dependant dropdown menus are based on Ajax technology, but they wouldn´t help you much in this situation I fear. However, I fear it´s fruitless trying to do the Insert Record form with ADDT in this case, as the whole form isn´t "ajaxified", means one would have to define "ajax regions" within that form, and that´s not supported by ADDT right out of the box.

              -----
              Do any of the spry controls fit the bill?
              -----

              So far I´ve tried that successfully with ADDT´s Dynamic Lists, but now with forms yet

              ------
              Or is there a way to use the Spry Utilities extension to requery the table on some action?
              ------

              As you can generate XML data from recordsets by e.g. using ADDT´s "Export Recordset as XML" component, it should be possible to generate a dropdown menu (actually a Spry Region) which retrieves its values/labels from that dynamically generated XML source and refreshes itself.

              All in all, I think you´d better consider creating an Insert Record form that´s *completely* built with Spry (or other frameworks like jquery or ext). However I assume that all this is "virgin soil" to most Dreamweaver/ADDT users, because SPRY is still declared "beta", it´s currently the only framework integrated in Dreamweaver, and complete/advanced "how to build a data centric PHP applications with SPRY" tutorials are hard to find.

              Cheers,
              Günter Schenk
              Adobe Community Expert, Dreamweaver
              • 4. Re: Requery Drop Down after new record added
                Level 1
                Thanks again Gunter,

                Sorry, I've been out for a few days. I ended up solving the problem by adding a preform search form to search for the buyers in the table before hitting the form. If the buyer isn't there it's added before going to the form. Works for me.

                I do have another question about a javascript I've been trying to get working on the same form. It converts numbers in one field to words in another (http://javascript.about.com/library/bltoword.htm) and looks fairly simple, but I think the way ADDT creates the fields names I can't figure out how to make it work. I was able to get it to work on a simple html form, but not the ADDT form. Here's some code with the two fields and the button that calls the javascript. Below that is the call in the head section. The link is also there, but I don't need to post it.

                I know this can work but I really could use some help.

                Thanks for any help

                <td class="KT_th"><label for="guarantee_<?php echo $cnt1; ?>">Guarantee:</label></td>
                <td><input type="text" name="guarantee_<?php echo $cnt1; ?>" id="guarantee_<?php echo $cnt1; ?>" value="<?php echo KT_escapeAttribute($row_rscontracts['guarantee']); ?>" size="10"/>
                <?php echo $tNGs->displayFieldHint("guarantee");?> <?php echo $tNGs->displayFieldError("contracts", "guarantee", $cnt1); ?>
                <label>
                <input type="button" onclick="form1.price_text_1.value = toWords(form1.guarantee_1.value);" value="Convert to Text" />
                </label></td>
                <td width="106" class="KT_th"><label for="foreign_exchange_<?php echo $cnt1; ?>">Curreny:</label></td>
                <td width="150"><select name="foreign_exchange_<?php echo $cnt1; ?>" id="foreign_exchange_<?php echo $cnt1; ?>">
                <option value=""><?php echo NXT_getResource("Select one..."); ?></option>
                <?php
                do {
                ?>
                <tr>
                <td width="109" valign="top" class="KT_th">Price Text:</td>
                <td width="197" valign="top"><span class="KT_th">
                <textarea name="price_text_<?php echo $cnt1; ?>" cols="32" id="price_text_<?php echo $cnt1; ?>"><?php echo KT_escapeAttribute($row_rscontracts['price_text']); ?></textarea>
                </span></td>

                This is in the head section:
                <script language="JavaScript" type="text/javascript">
                <!--

                // Call num to words script
                var words = toWords(num);
                //-->

                </script>
                • 5. Re: Requery Drop Down after new record added
                  Günter Schenk Level 4
                  Hi Tony,

                  I reckon the problem is, that ADDT´s "multi update" forms use a certain field naming convention (whatevername_) which gets happily ignored by your "onclick" event handler, and I think you´ll just need to take this naming convention into account in the onclick handler.

                  The ADDT field names are:

                  guarantee_
                  price_text_

                  ...so please try with this "PHP in Javascript" fix:

                  onclick="form1.price_text_.value = toWords(form1.guarantee_.value);"

                  Works ?

                  Cheers,
                  Günter Schenk
                  Adobe Community Expert, Dreamweaver
                  • 6. Re: Requery Drop Down after new record added
                    Level 1
                    Hi Gunter,

                    Well I made the change you suggested, but I can't browse the page (see my latest post re the fatal error in wdg class)until I get the other issue fixed. I may have already tried this, but I can't remember. At first I thought that I may have needed to add something to the call in the head section. Should that be something other than num in the arg?

                    I'll let you know if this worked as soon as I can get some help on the fatal error.

                    Here;s the error if you can help on that too I would really appreciate it.

                    Fatal error: Call to a member function FieldCount() on a non-object in C:\wamp\www\rootsadmin\includes\wdg\WDG_JsRecordset.class.php on line 33

                    Thanks again for all the help,

                    Tony Galfano