The issue is this:
In my APP, I need to knw if a SELECT element is visible or not in the DOM under the MATERIALIZE framework. (Please do not mark this question as already discussed in here until you read it until the end.
So far I have been using document.getElementById('xx').offsetParent!==null to check that, and it has worked fine for me so far.
However, since I migrated my HTML code to Materializecss, my visiblity checking function does not work anymore.
This piece of code works perfectly in pure HTML
<div class='input-field col s12'>
<select name='V18' id='V18' />
<option value='' disabled selected>Select</option>
<option id='V18_1' value='1'>Choice 1</option>
<option id='V18_2' value='2'>Choice 2</option>
<option id='V18_3' value='3'>Choice 3</option>
</select>
</div>
<script>
if
(document.getElementById('V18').offsetParent!==null){
alert('Select is visible');
}else{
alert('Select is NOT visible');
}
</script>
Once I initialize the Selects in Materialize css, by calling the function $('select').material_select(), my visibilty checking function does not work anymore.
I have already tested all the options discussed on these links, and none of them work for Materialize selects:
Check if element is visible in DOM
How do I check if an element is hidden in jQuery?
My, question is...How can I check if a SELECT element is visible or not within the Materialize Framework? Seems that after initializing the selects, they loose some critical Javascript properties, somehow.
Does anyone have the same problem?
The workaround that I found for materializecss was to treat selects in a different way from radion buttons and texts,
For selects I detect visibility by using: window.getComputedStyle(element)).display === 'none'
For the rest kind of elements I detect visibility by using: "document.getElementById(element).offsetParent!==null"
Related
I am experiencing some performance issues in Vue after migrating from an old angularjs app.
The page displays a list of available reports with a settings button alongside each report.
Likewise each report has among other things a property called worksheet which indicates the name of the worksheet driving this report.
So for example something like this
<div class="list" v-for="(report,repidx) in filteredReports" v-show="hideDemo.indexOf(report.Name) == -1">
<h2>{{report.Name}}</h2><button #click="report.showsettings=true">Settings</button>
<div v-show="report.showsettings">
<select name="worksheet" v-model="report.worksheet">
<option v-for="worksheet in allworksheets">{{worksheet.Name}}</option>
</select>
</div>
</div>
When clicking on the settings button a dropdown list is exposed which indicates all the available worksheets that could be assigned to the selected report
"allworksheets" is an array of objects which might contain a 1000 worksheets.
Having it populated on the DOM (using v-for) for each report in the list does not seem efficient and causes tremendous performance issues on page loading and also during operations eg clicking on Settings button. (Surprisingly this worked perfectly fine in angularjs).
I tried switching to using a computed property but that also didnt help.
It gets even more complicated because the angular approach also had an additional option group which displayed SIMILAR worksheets to the currently selected one. For eg something like this
<select name="worksheet" v-model="report.worksheet">
<optgroup label="similarworksheets">
<option v-for="sm in similarworksheets(report.worksheet)">{{sm.Name}}</option>
</optgroup>
<optgroup label="allworksheets">
<option v-for="worksheet in allworksheets">{{worksheet.Name}}</option>
</optgroup>
</select>
In this case "similarworksheets" is a method that accepts the report.worksheet as a parameter and returns a filtered version of allworksheets, showing only SIMILAR worksheets. This obviously makes performance even worse!
Can someone suggest a better way to approach this given the fact that I need to stick to this structure - more or less - ie a dropdown list available for each selected report.
Thanks
Goodnight.
Working with VUE and MaterializeCSS I'm having problems using since I need to list a number of options from an array of objects filled in from an Ajax request but apparently VUE is hiding the information by creating a new under the main one.
Then I would like to know if anyone knows how to deactivate an element of the Materilizecss framework? In this case . Thank you.
If someone works for you:
Add the browser-default class to the but indicate in the display: block style because for some reason it hides it.
<select class="browser-default" style="display:block" v-model="category_id">
<option v-for="category in arrayCategories" :key="category.id" :value="category.id" v-text="category.name"></option>
</select>
Greetings.
I'm using webdriverio for QA testing and need to change the selected value of a <select>. I am able to enter text in textboxes and click buttons etc just fine but, when I am unable to use browser.selectByValue() to change the selected option for a select on the page.
What seems to happen is the element beneath where the option appears is being clicked instead (the evidence for this is that the element underneath is a hyperlink and navigation occurs where the select's selected option should have changed.
I'm testing against Firefox 45 on Linux Mint with Selenium Standalone server 3.3.1 and geckodriver 1.5.0, webdriverio 4.6.2 and wdio-mocha-framework 0.5.9.
Edited to include HTML
I've changed the values/text but otherwise this is the exact HTML I'm testing against.
<select id="ember1268" tabindex="0" class="ember-view blue-background x-select">
<option id="ember1278" value="option1" class="ember-view x-option">Option 1</option>
<option id="ember1280" value="option2" class="ember-view x-option">Option 2</option>
<option id="ember1282" value="option3" class="ember-view x-option">Option 3</option>
<option id="ember1284" value="option4" class="ember-view x-option">Option 4</option>
</select>
Further edit
I just tested this again on Windows against Firefox 52 and it works as it should. I have a theory that the reason it fails in Linux is that it is running in a VM and running quite slowly. Could it be that the test is trying to click the option before it's actually appeared? If so, is there any way to add a delay to allow the option to appear?
Edit to include JS code snippet
This is the code I'm using to change the selection.
var clientSelect = browser.element('select');
clientSelect.selectByValue('option1');
I know there are plenty of answers to this question already, but none of them work now. Probably due to Bootstrap update.
Here is jsfiddle: http://jsfiddle.net/N0ir/Yh33b/
Who can figure this out?
<select>
<option value="1">Misha, davai po novoi</option>
</select>
.caret {
display:none;
}
You cannot change or alter the caret using css as the select element is generated by the browser by default (that's why they look different from browser to browser). You need to use js/css to get the change you want as well as keep it browser compatible. Here is a link to a nice one for Bootstrap users:
http://silviomoreto.github.io/bootstrap-select/3/
Ok, so I'm building an app using Dojo 1.8, and I have a custom widget with a template similar to this...
<div>
<label for="tag">Select something: </label>
<select id="tag"
data-dojo-attach-point="tag"
data-dojo-type="dijit/form/Select">
<option value="0">option 0</option>
<option value="1">option 1</option>
</select>
</div>
However, when the template gets rendered, the widget defines a new id, which makes the tag useless. I've tried googling this, but all my searches just direct to the Dojo documentation since they have attributes called labels but have nothing to do with the HTML label tag.
What is the proper why to do this?
In the situation you describe, you can simply place the label around your <select> and dispose with the for/id attributes. see Stackoverflow question:
How do I align two dojo widgets next to each other?, also see: w3 tutorial on label use
Also, if you want to actually use Ids in a widget template, see:
How do I create unique IDs in a Dojo widget template?
Using ids directly (ie. hard-coding them, not assigning them on-the-fly as in the above link) is not encouraged. The reason for this is that a template is meant to used over and over again in the creation of widgets.
In theory, it could be used to create multiple widgets on one page. Hence, in that situation you would have an id conflict. Each HTML id, on any one page, needs to be unique.