JQuery mobile select menu not working properly - ruby

I'm working on a Ruby and Sinatra project, and for a particular page I'm using jQuery mobile to create a mobile version of the page. I'm using knockout.js in the project as well.
I have a select box which appears correctly but when I make a selection, its text doesn't change though the value changes.
Here is my HAML code:
#subscriptions-content-div{'data-role' => 'content'}
%ol{'data-role' => 'listview', 'data-inset' => 'true', 'data-bind' => 'foreach: misspelt'}
%li
%h3{ 'data-bind' => 'text: show_name'}
- if shows.empty?
No Shows in Database
- else
%select#show
%option{'value' => 'no_choice', 'data-placeholder' => 'true'} Select a Show
- shows.each do |show|
%option{'value' => show.id}
= show.name
%button.btn{ 'data-bind' => 'click: $root.resolveSubscription', 'data-inline' => 'true', 'data-icon' => 'check', 'data-theme' => 'a'}
Save
This is the HTML I get when I view the page source:
<div data-role='content' id='subscriptions-content-div'>
<ol data-bind='foreach: misspelt' data-inset='true' data-role='listview'>
<li>
<h3 data-bind='text: show_name'></h3>
<select id='show'>
<option data-placeholder='true' value='no_choice'>Select a Show</option>
<option value='50594de40ea69713630000de'>
The Night Show
</option>
<option value='50594de40ea69713630000df'>
Another Show
</option>
<option value='50594de40ea69713630000e0'>
Yet Another Show
</option>
</select>
<button class='btn' data-bind='click: $root.resolveSubscription' data-icon='check' data-inline='true' data-theme='a'>
Save
</button>
</li>
</ol>
</div>
The menu has 'Select a Show' as the title. When I select something else, this doesn't change but the value changes. I can tell it changes when I get the value of the selected option. Why won't the text change?

The solution is to defer the selects' initialization until after the KO bindings have been applied. I added data-role="none" attributes to the select elements and manually called $.selectmenu() after ko.applyBindings() - as seen here: http://jsfiddle.net/aib42/xtz5B/

If you are dynamically adding options to the select menu, then refreshing the select menu can be helpful.
$('#show').selectmenu();
$('#show').selectmenu('refresh');

Related

ElementNotVisibleError - A Specific Watir-Webdriver Issue

Trying to do
b.select_list(:name => "bedroomsMin").select '3+ Beds'
on
<div class="beds col-sm-2 hidden-xs">
<div class="form-group">
<select class="form-control wide" name="bedroomsMin">
<option value="null">All Beds</option>
<option value="0">0+ Beds</option>
<option value="1">1+ Beds</option>
<option value="2">2+ Beds</option>
<option value="3">3+ Beds</option>
<option value="4">4+ Beds</option>
<option value="5">5+ Beds</option>
</select>
</div>
</div>
but get the following error:
element not visible: Element is not currently visible and may not be manipulated (Selenium::WebDriver::Error::ElementNotVisibleError).
This list selector is contained in a dropdown element that is clicked like this:
b.link(:class => 'btn-open-filers').when_present.click
How can I select if it's not visible? Is there a way to force visibility?
Sounds like a timing issue. When the link is clicked, the dialog containing the select list may not appear before Watir tries to interact with it.
Try waiting for the select list:
b.select_list(:name => "bedroomsMin").when_present.select '3+ Beds'
Looks like the <div class="beds col-sm-2 hidden-xs"> having hidden may have something to do with it.
Also it appears you're are only checking for when the element is present, which is to say if it loads in the html but is not visible it'll still return true.
Here's a quick read on that:
What's the difference between `visible?` and `present?`?
Since you have it clicking the dropdown after it checks for it's presence, there might be a timing issue. In which case it may check that the dropdown is present in the DOM but is not actually opening the dropdown.
May want to try something like:
dropdown = b.link(:class => 'btn-open-filers')
dropdown.click if dropdown.visible?
b.select_list(:name => "bedroomsMin").select '3+ Beds'
Watir is designed to interact with the elements that a user can interact with. So if it isn't visible to a user, you shouldn't be able to interact with it. So, it's feature, not a bug. :)
That being said, it isn't clear from your post what action is causing the error. This code will wait for the select list to become visible before you try to select an option inside it:
b.link(class: 'btn-open-filers').when_present.click
b.div(class: 'form-group').wait_until_present
b.select_list(name: 'bedroomsMin").select '3+ Beds'
Justin's answer is functionally the same as this, and when_present is probably more elegant.

How to avoid assigning the index of selected drop box item when inserted to db instead of actual value in drop box?

{!! Form::select('subject', array('' => 'Select A Subject')+$subject, null,['class' => 'form-control']) !!}
Above is the drop box code. That takes values from db and display correctly at the drop box. But after it is selected it gets the index.The inspect of that output as follows.
<select class="form-control" name="subject"><option value="" selected="selected">Select A Subject</option><option value="1">English</option><option value="3">Environmental Studies</option><option value="2">Maths</option></select>
How to fix that problem?
Try This:
$subList = ['' => 'Select A Subject'] +$subject;
{!! Form::select('name', $subList , Input::old('name') , array('class'=>'form-control')) !!}

Rspec + Capybara: Validating select options using xpath

I have an HTML document (there is a DIV with an ID of "countries" that wraps this code below), and in that I need to -
Validate the options in the select. I tried this but this is not valid.
expect(page).to have_xpath(('//*[#id="countries"]//select')[1],
:options => ['US CAN GER POL'])
Validate that the second select is disabled
Validate that CAN is disabled in the first select
Validate that POL is selected in the first select
Change the selected option to GER in the first select
<li>
<fieldset>
<select>
<option value="US">USA</option>
<option value="CAN" disabled>Canada</option>
<option value="GER">Germany</option>
<option value="POL" selected>Poland</option>
</select>
<fieldset>
<li>
<li>
<fieldset>
<select disabled>
<option value="US">USA</option>
<option value="CAN">Canada</option>
<option value="GER">Germany</option>
<option value="POL">Poland</option>
</select>
<fieldset>
<li>
I appreciate any help that you can provide. Thanks!
Word of warning, I personally still use the should syntax for rspec, and I also use css selectors versus xpath. I simply find them easier to read.
(1) Because you have two dropdowns without any specific IDs or class names identifying one from the other, I would use all to restrict the context of your expectations
all('#countries select')[0].should have_text('USA Canada Germany Poland')
(2) Same concept as above, restrict the scope. Second fieldset should contain a disabled dropdown.
all('#countries fieldset')[1].should have_css('select[disabled]')
(3) all('#countries select')[0].should have_css('option[disabled]', :text => 'Canada')
(4) Same answer as #3 but with different attribute and text
(5) all('#countries select')[0].find('option', :text => 'Germany').click

Laravel 5 dropdown box do not pass back old value upon validation fail

I have a quick question. I made a dropdown box for gender selection in my registration form that looks like this:
<div class="col-md-6 col-sm-6">
<select name="gender" value="{{ old('gender') }}" class="form-control">
<option value=null>------ Gender ------</option>
<option value="male">Male</option>
<option value="female">Female</option>
</select>
{!! MessagerService::setInlineError($errors->first('gender')) !!}
</div>
So what I do is upon a validation fail, the selected gender is not passed back to the form. Any ideas what I have done wrong? Thank you.
You don't have to write plain HTML. You can take advantage of Laravel Form Builder. In Laravel 5 it is not bundled by default, like it was in 4.2, so first you need to require it. Go to your project root and in terminal write:
composer require "illuminate/html":"5.0.*"
Then go to config/app.php and under providers add
'Illuminate\Html\HtmlServiceProvider',
You can register also those two facades under aliases:
'Form'=> 'Illuminate\Html\FormFacade',
'HTML'=> 'Illuminate\Html\HtmlFacade',
After that you are ready to use Form facade to create your select with one simple line of code which will handle old input values:
{!! Form::select('gender', ['' => '--Gender--', 'male' => 'Male', 'female' => 'Female']) !!}
It is as simple as that. You can check the documentation to find out more useful methods of the Form facade.

Joomla Chronoforms Dynamic To

I have successfully created a basic Chronoforms form with the standard 'To' field sending the form data in an email to one recipient. However, I would like the 'To' field to become a 'Dynamic To' that will send the form to different users based off of the value of one of the dropdown fields I have in the form. I couldn't find any good documentation on how to use the 'Dynamic To' or accomplish this.
Anyone have any thoughts?
In chronoform you use the dynamic fields simply by writing the name of the form field into the respective E-Mail field.
So if the name of your dropdown is email_choice you write email_choice into the "Dynamic To" field of the E-Mail setup box and you're good to go.
How to show a drop down list of email recipients without displaying the email addresses publicly:
1. ChronoForms v3
Your drop down list in your HTML code will look something like this:
<div class="form_item">
<div class="form_element cf_dropdown">
<label class="cf_label" style="width: 150px;">Person to Contact:</label>
<select class="cf_inputbox" id="select_0" size="1" title="" name="Attn">
<option value="">Choose Option</option>
<option value="President">President</option>
<option value="Secretary">Secretary</option>
<option value="Treasurer">Treasurer</option>
etc
Enter this code in the 'On Submit code - before sending email' field:
<?php
$email_list = array(
'President'=>'president#organisation.com',
'Secretary'=>'secretary#organisation.com',
'Treasurer'=>'treasurer#organisation.com'
);
$MyForm =& CFChronoForm::getInstance('Contact');
$MyFormEmails =& CFEMails::getInstance($MyForm->formrow->id);
$MyFormEmails->setEmailData(1, 'to', $email_list[$_POST['Attn']]);
?>
This assumes your form name is "Contact".
In "Setup Emails", enter "Attn" in the "To" field.
2. ChronoForms v4
Your drop down list in your HTML code will look something like this:
<div class="ccms_form_element cfdiv_select" id="who_to_contact__container_div">
<label for="Who">Who to Contact:</label>
<select size="1" label_over="0" hide_label="0" id="Who" class=" validate['required']" title="Who" type="select" name="Who">
<option value="President">President</option>
<option value="Secretary">Secretary</option>
<option value="Treasurer">Treasurer</option>
etc
Enter some Custom Code In the Submit section with "Mode" set to "Controller":
<?php
$who = JRequest::getString('Who', 'Webmaster', 'post');
$emails = array(
'President' => 'president#organisation.com',
'Secretary' => 'secretary#organisation.com',
'Treasurer' => 'treasurer#organisation.com'
);
$form->data['Attn'] = $emails[$who];
?>
In Email -> Dynamic, set "Dynamic To" to: Attn
References:
http://chronoengine.com/forums/viewtopic.php?f=2&t=15263&p=45265
http://chronoengine.com/forums/viewtopic.php?f=5&t=16272&p=42909
http://chronoengine.com/forums/viewtopic.php?f=2&t=16839&p=45601

Resources