Code Monkey home page Code Monkey logo

Comments (6)

adamcoulombe avatar adamcoulombe commented on July 17, 2024

if you are setting the select value programatically, you need to trigger an update:

var $cs = $("#P107_EDIT_VATID").customSelect();

$cs.val(117).trigger('update');

from jquery.customselect.

simakas avatar simakas commented on July 17, 2024

in my case its a place where values are loaded into drops and they already have customSelect assigned in page header.
quite a nasty workaround to get display value populated...

var dd = document.getElementById("P107_EDIT_VATID");  // item
readXML(ret, "VAT", "P107_EDIT_VATID");                      // procedure populating item value (could be static)
var $cs = $("#P107_EDIT_VATID");                                //.customSelect() is already present
try
  {$cs.val(dd.options[dd.selectedIndex].value).trigger('update');  // updating value based on selected index
  }
catch(e)
  {dd.value = '0';                                                    // if value was not set, set it to your null/default value..
   $cs.val('< Choose something >').trigger('update');  //...null/default dropdown text value
  }

from jquery.customselect.

adamcoulombe avatar adamcoulombe commented on July 17, 2024

your dd variable is the same as $cs[0], so you have a lot of redundance here. If you are populating the dropdown using readXML, the select value will be set already. So all you should need to do is trigger an update. If you actually are loading XML this needs to happen in the callback otherwise you will fire the update way before the values are actually loaded.

readXML(ret, "VAT", "P107_EDIT_VATID");  

after readXML is successful...

// $cs.val() == dd.value - no need to maintain two different vars
var newVal = $cs.val() || '< Choose something >';
$cs.val(newVal).trigger('update');

from jquery.customselect.

simakas avatar simakas commented on July 17, 2024

yeap, way less overhead, just had to add 'return value', not 'display value' for it to work.

readXML(ret, "VAT", "P107_EDIT_VATID");  // populate dropdown item
var $cs = $("#P107_EDIT_VATID");             // issue variable
var newVal = $cs.val() || '0';                         // option set + default return value (or text as suggested above)
$cs.val(newVal).trigger('update');                 // trigger an update

from jquery.customselect.

teambalthazar avatar teambalthazar commented on July 17, 2024

Might be worth updating the answers in here to .trigger('render'); instead of .trigger('update) for any googlers (like me) who might find their way here. I assume this is something that has changed in the plugin over the last 2 years as update didn't work for me, but render did.

from jquery.customselect.

MuhammadFaizanKhan avatar MuhammadFaizanKhan commented on July 17, 2024

I have used these two method but still i am failed to select dropdown option using code.

  var mainProjectDropdown = $jq("#mainProjectId").customselect();
            mainProjectDropdown.val(mainProjectId).trigger('render');

The second way:

  var mainProjectDropdown = $jq("#mainProjectId").customselect();
  mainProjectDropdown.val(mainProjectId).trigger('update');

from jquery.customselect.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.