简体   繁体   中英

$(“#id”).val() return option text for a dojo.filteringselect object

We have a dojo filtering select object but have to validate by jquery. Now the problem is

var value= j("#filteringSelectId").val();

value only returns the text of selected option instead of the selected value... it seems dojo has made some changes to the original Dom object, as the dojo select object is identified as input#filteringSelectId.dijitReset

So how can I get the dojo filteringSelect value instead of option text by jQuery? Is it doable?

If you look at the actual HTML a filtering select creates, it will look something like this (taken from dojo's reference docs )

<div class="dijit dijitReset dijitInline dijitLeft dijitTextBox dijitComboBox dijitValidationTextBox" id="widget_stateSelect" role="combobox" aria-haspopup="true" data-dojo-attach-point="_popupStateNode" widgetid="stateSelect">
    <div class="dijitReset dijitRight dijitButtonNode dijitArrowButton dijitDownArrowButton dijitArrowButtonContainer" data-dojo-attach-point="_buttonNode" role="presentation" style="">
        <input class="dijitReset dijitInputField dijitArrowButtonInner" value="&#9660; " type="text" tabindex="-1" readonly="readonly" role="button presentation" aria-hidden="true" />
    </div>
    <div class="dijitReset dijitValidationContainer">
        <input class="dijitReset dijitInputField dijitValidationIcon dijitValidationInner" value="&Chi; " type="text" tabindex="-1" readonly="readonly" role="presentation" />
    </div>
    <div class="dijitReset dijitInputField dijitInputContainer">
        <input class="dijitReset dijitInputInner" type="text" autocomplete="off" data-dojo-attach-point="textbox,focusNode" role="textbox" aria-required="true" tabindex="0" id="stateSelect" value="California" />
        <input type="hidden" name="state" value="CA" />
    </div>
</div>

Based on this information, you could probably build a selector like:

$('#filteringSelectId .dijitReset input[type="hidden"]').val()

If you just need to get the value in javascript (I can't say I'm familiar with jquery validation), you could do something like

dijit.byId('widgetId').get('value');

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM