TACTIC Open Source
Look Ahead - Add item if doesnt exist - Printable Version

+- TACTIC Open Source (http://forum.southpawtech.com)
+-- Forum: TACTIC Open Source (http://forum.southpawtech.com/forumdisplay.php?fid=3)
+--- Forum: TACTIC Discussion (http://forum.southpawtech.com/forumdisplay.php?fid=4)
+--- Thread: Look Ahead - Add item if doesnt exist (/showthread.php?tid=191)

Look Ahead - Add item if doesnt exist - dankitchen - 01-12-2021

I am trying to see if I can get the LookAheadTextInputWdg to work as a look ahead on the name column of a simple look up table then if the user does not select someting, insert the text they typed in as a new entry in the lookup table.  I somewhat have this working as I noticed that using spt.api.get_input_values returns the list of options/results as name/value pairs.  Its seems that what the user types ends up being the last two items in the array.  If the second last item is empty, it indicates that there wasnt a result and I should create a new entry in the LUT.  

I guess the question is if there is a simpler\built-in way to do this?  I have an example below of my element and the test code I put together to see if it could work.

<div class="test_top" style="width:400px; height:400px">
  <h2>Look Ahead Test</h2>
  <button class="save">SAVE</button>
  <div class="form-item">
    <div class="form-input">
      <element name="city">
        <display class="tactic.ui.input.LookAheadTextInputWdg">
          <hint_text>Type the city</hint_text>

And the save button behavior

var server = TacticServerStub.get();

var test_el = bvr.src_el.getParent("test_top");
var input_values = spt.api.get_input_values(test_el);

if (input_values.city[input_values.city.length-2]) {

  alert("in list");

else {

  server.insert("test/city", {'name': input_values.city[input_values.city.length-2]});
   alert("not in list - added");