JS Snippet

0
Hello, I'm trying to focus on the first visible input field when a button is clicked. I am using 'JavaScript Snippet', with jquery 1.12.4. Looks like the focus action is getting overridden by something. I do see a flash when the field gets focused but then its off. I tried putting the snippet in the beginning, as well as at the end of the page. Fields are initialized inside a data view, with microflow as the data source. The button also resides inside the same data view. Any idea what could be overriding my js snippet?
asked
2 answers
1

Hi Vertika,

Maybe you can try using the javascript button. This allows you to execute javascript before executing a microflow. 

https://appstore.home.mendix.com/link/app/27064/Mendix/JavaScript-Button

 

Also it might help to share your javascript. 

answered
0

Hi Austin, Thank you for the reply. I downloaded the JavaScript button.mpk from app store but I don't see it in Add-Ons or in Project Explorer. How I'm supposed to use JS button in modeler?

My current js code is:

$('.focusField').find('input:first').focus();

where '.focusField' is class assigned to all input fields that needs to be focused at some click.

Earlier, I tried:

 $(document).ready(function () { $('input[type="text"]').on('click', function () { this.select(); }); }) 

and before that, I tried:

var btn = $('.orangeBtn').eq(5); btn.click(function() { $('.focusField').find('input:first').focus(); }); 

where '.orangeBtn' is the class assigned to buttons in different divisions and will be clicked at some point. (this code worked fine in JSFiddle online editor).

answered