How to control select2 component programmatically without jQuery? The code is going to be executed using Selenium and since I don't have access to the jQuery object (it's bundled with Webpack), it has to be controlled using pure JS.
I tried simulating user click like this:
document.getElementById('select2').click()
but it doesn't open. What I'm trying to achieve is:
open Select2
type something inside its search box to trigger the ajax call and shows possible options
select an option by text
You can try this workaround: document.querySelector("#example + span > .selection > span") and then trigger click. Fiddle to check: https://jsfiddle.net/zeLbk6s3/2/
You have to trigger "click" on proper element.
Related
I am using ng-multiselect-dropdown for showing some checkbox and also filtering them based on search text. Now I wnt to detect or call a function every time user clicks in the search text but since it's a plugin, how can i detect or add the click event ?
Refering to ng-multiselect-dropdown
You can not detect or add the click event.
But you can achieve this using ng-select
Referring to the above ng-multiselect-dropdown link, there is an ability to detect on-keypress (which is what I wanted).
See (onFilterChange)="onFilterChange($event)"
I am trying to automate a website test using JavaScript. Part of my tests include clicking a button that has a type, but no id.
I've tried to do this using a jQuery code that I found online but it didn't work. Is there any way to simulate the click using the type of the button?
This is the HTML of the button I am trying to target:
<button type="submit">Go</button>
You can use the jQuery attribute selector, $(element[attribute='value'])
$('button[type="submit"]')
You can have a look at the documentation here if you want to understand more of the selector - you can do things such as select based on the start / end of an attribute, or if it is not the value you give
I'm using selectize, and I want to show a few options without clicking selectize input. So I use $('.selectize-input').click() but it doesn't work. How to show a few options without clicking input?
Assuming that you bind selectize plugin something like $('.selectize-input').selectize(options), you should be able to use API's open method like this:
$('.selectize-input')[0].open();
I am using the fasw javascript library - http://www.fasw.ws/faswwp/non-jquery-page-transitions-lightweight/ - to do page transitions in a webapp. It can only appear to be triggered via a data attribute on a link.
$('body').prepend('<a class="decider_link_trigger" href="#">[Trigger]</a>');
$('.decider_link_trigger').attr('data-ftrans', 'flip');
$('.decider_link_trigger').attr('href', selected.result);
$('.decider_link_trigger').trigger('click');
The above code adds such a link to the page with the provided data-ftrans attribute and is even clickable manually, but I can't figure out how to submit the link with jQuery (or event Javascript).
I cannot do a manual window.location.href = selected.result; as this will not use the transition library.
Thanks!
How can I force any change to a checkbox (inside a form) or to a drop-down menu selection to cause a HTTP POST to be issued by the browser?
Bandwidth is not an issue, page reloading is not an issue and I don't want to go the full AJAX route.
What I really want is an HTTP POST to be done when the user clicks on a checkbox (or selects something from a drop-down menu), etc. without the user having to click 'Submit' after its change.
Maybe it should be done with some JavaScript on the client-side? (I couldn't succesfully Google anything)
Use Javascript. Add onchange="document.getElementById('myFormId').submit()" to the elements, or do this programatically. myFormId must be replaced by the HTML id of the form element.
You could use the JavaScript onchange event to then call the submit() function on the form.
if you have a form already set up just put a class to the element you want to use as trigger and then
for select
$(".classname").change(function(){
$("#formid").submit();
});
for checkbox/radio
$(".classname").click(function(){
$("#formid").submit();
});
AFIK it can't be done without client-side scripting. The easiest way would be to trigger the submit event for every form change. With jQuery it's done with the following code:
<script type="text/javascript">
$(function() {
$("input[type=checkbox],input[type=radio],select").change(
function(evt)){evt.target.form.submit();}
);
});
</script>
If you don't use jQuery, you'll have to write some boilerplate event handling code. See this introduction for more info on JavaScript event handling.