How to fill dynamic form fields using capybara - ruby-on-rails-4

I have a form that contains a select box and a text field.
The text field is displayed dynamically based on the selectbox selection. If the value of selectbox is "Yes", then the text field will be displayed and vice versa.
I am running an rspec test and filled the select box value with "Yes"
select 'Yes', from: 'property[have_water_bills]'
Now i want to fill a value on the text field
fill_in 'property[irrigation_cycle_count]', with: 5
But i am getting the following error.
Capybara::ElementNotFound:
Unable to find field "property[irrigation_cycle_count]"
That is, capybara cannot find the dynamic element. Does anyone know how to fix this?

Poltergeist doesn't gemerate a click event when choosing an item from a select. It generates a focus on the option, change on the select, blur on the option. It is more like if a user selected the option with keyboard instead of using a mouse. You probably should be doing the logic to display your text field on the change event anyway so that it works if people use a mouse or a keyboard to navigate around your page. It also makes more sense to run your show/hide logic on the change event because that's what you actually care about, not clicks.

Finally got this to work using the following piece of code
page.execute_script("$('#have_water_bills').val('true').trigger('click')")

Related

Allow to check only one checkbox in Oracle apex

I created classic report with check boxes using apex_item.checkbox .I want to know how to allow to check only checkbox.That is if i click more than checkbox alert message should display.Please help me out
Thanks in advance.
If you want to do this via dynamic actions then you will want do a dynamic action on event Change, Selection Type jQuery Selector and the jQuery Selector being input[name = "something"]
This something you can figure out by running the page as is, and if you click F12 on your keyboard, the console will open. Then select the element that is your checkbox and find its name and this should be your "something". Play around with this to make it work(set the DA to run an alert or something to see when its triggered).
Then perhaps have a page item that is filled when this DA runs, and then if the page item is already filled and the DA runs, throw up an error saying you cant do this.
Or if you want to clear the previously checked box, you could save the name of currently checked box in the page item. And have the DA do a javascript function that clears the value in the field in the page item.
Basically have the DA get the name of the checked box from the item where you store it, and do some dynamic javascript. When I needed to do something similair I created a var in javascript that was formed like $s(" + checked_box + ", ""); assembling this with concat. And then do an eval(this_concacted_instruction).
I hope my ramblings guide you to a solution. I remember the first time I was working with this stuff I took a week to get one page sorted(although it was a bit more difficult than your problem), but it felt sooo good when I got it done. So keep on trying.
GLHF

Can I add a 'shortcut' link to a Django form which edits a field and saves everything?

I have a Django (crispy) form with many tabs which all contain many fields. Each of these tabs has an Active boolean field. The first tab of my the form contains an overview, listing all the tabs.
Now I would like to know if there is some way to have a link on that overview tab which would in theory toggle the corresponding boolean field on one of the tabs and save the result. Right now the user can go to the specific tab, check or uncheck the value and save it, but they want some sort of shortcut so they can do it in one click.
Would that be possible at all? And how could I achieve this ?
So clicking the Activate / Deactivate in this list should be the same as :
Going to the corresponding tab and checking / unchecking the available field and pressing the save button.
You can use javascript and do onchange for checkbox. In the script you can call the views to save the value to database and return to same page.

Sitecore 8, MVC, Experience Editor: How to make a rendering refresh after a Field Editor Button has been used

We have a rendering listing the selected items in a TreeSelect in the current item. In our case we call them "Tags" (1)
We have added a Field Editor Button to the component to let the editor change selected items. (2) (As described on for example Adding a custom component)
When an editor clicks (2) the editor window (3) it is opened in a dialog. The editor may select different items(called tags in our case) using the TreeSelect.
When the editor presses the ok-button (4) the values are set.
Now to the problem:
The values are actually set as they get stored when the editor presses the Save button but we want our list on the page (1) to immediately reflect the set items when the editor presses the ok-button (4), i.e. before having to actually save the whole item.
How do we achieve that?
(I am in contacts with Sitecore support but so far I have not gotten any answers...)
Update
After a lot of conversation with the support we still have no useful solution.
We tried turning it into a field renderer displaying the links.
What worked was:
The field do get updated when you have edited it in the popup field editor. (but...)
It looks good the first time when page is loaded.
You can make a WebEdit button with commands to edit the field and add it as Custom button to the field (register <command name="webedit:fieldeditor" type="Sitecore.Shell.Applications.WebEdit.Commands.FieldEditor, Sitecore.Client"/> and set Click on the button to webedit:fieldeditor(command={3473DDA1-2983-493C-AF7A-054C75AA7AD3},fields=NameOfField where the guid points to itelf and an "Icon" is set on it.)
What didn't work was:
The field get updated by the raw value, not what I want to display. Server code is involved, but not in the rendering of html-code.
When I want to edit the value in the field editor, the value sent to the field editor is not the raw value but what actually is displayed on the page. (I guess this can be solved somehow)
The issue to the support turned into a feature request to let the server be involved in rendering the field, not just sending a new value to the JavaScript updating it. The server does the first rendering so when it already is involved in updating, it should be allowed to do the rendering the following times too.
We have decided to not spend more time on this right now (we have other things to do too.) and have a bad editor experience as the field not get updated until the editor actually saves the item.
Still we have no suitable solution for this issue. If you want to keep working on it and want a reference to my issue it is 439059.
This may not be useful here. I've done this in normal sites, but not in Sitecore. But, here's one possibility....
This is a situation where you would pass a callback function to the child popup window. This callback will cause the caller / parent window to re-read/re-load the information that was just updated by the child.
Example:
User presses (2) to open Editor Window(3) (Editor window is opened and the Callback function is passed as a parameter)
User presses "OK" button (4). The "OK" button event handler updates the changes, then calls the Callback function which re-loads the now updated information, and closes the popup window.
Once the popup closes, the parent window now displays the information that the popup/editor just updated.
This takes some client side javascript (jquery) development but it is quite do-able normally.

Custom Validation in Ektron Smartfrom Definition

I am working in Ektron 8.7.
I am trying to add a custom validation logic to my smartform definition.
I have a check box and text box fields in my smartform definition,i need to make the text box read only if the check box checked property is true.
The custom validation options available in the smartform editor fields doesn't have any such option.
How can i achieve this?
I have gone through custom validation knowledge base article in ektron(http://dev.ektron.com/kb_article.aspx?id=7420).
But i couldn't get the property of smartform element
in order to define the logic.Is this possible through XSLT?
Making a text box read only if a check box is checked doesn't really fall into 'validation' -- sounds like you want to use the relevance feature, which allows you to hide or show form fields based on values of other fields. For example, you could show a read only version of the field when the check box is checked, and an editable version when it is unchecked. You can additionally apply validation logic on the text box that's displayed. Here are some related resources to help you get going with this http://bit.ly/cXiaKd -- http://bit.ly/11gedde

Passing a text field value into popup page using URL

I am trying to pass the value of a text field from one page to another using the URL but failing miserably.
The reason for this is as follows:
I have an apex page which displays a machines properties (make, model, what products it makes, machine ID (:P1_INPUT)). Some machines can only make one product, other can make a variety.
I use a query to complete the following: If the machine only makes one type of product , the product number is displayed in :P1_item. If a machine can make more than one product it displays in :P1_item the world 'multiple'.
I want to build in the ability to click on a button next to :P1_Item, a popup appears with the products the machine makes if ‘multiple’ is displayed. I have the popup bit working but its not passing my :P1_INPUT from the page to the popup page text field :P3_OUPUT
The following code i have on the button, so when it is clicked, it opens a popup page (this works) and should populate the text field (P3_OUTPUT) with the value passed from P1_INPUT (this doesnt work).
My button is set to Redirect to URL and i have this in the URL target.
javascript:popupURL('f?p=&APP_ID.:HELLOWORLD:&SESSION.:::&P3_OUTPUT.:&P1_INPUT.')
I cant use a branch because i dont want the main page showing the machine properties to submit.
Your URL is wrong: f?p=&APP_ID.:HELLOWORLD:&SESSION.:::&P3_OUTPUT.:&P1_INPUT. : you want to provide a value for the item P3_OUTPUT while you have set &P3_OUTPUT. which is a substitution string and would put the value of P3_OUTPUT in the string.
You need to set the URL to f?p=&APP_ID.:HELLOWORLD:&SESSION.::::P3_OUTPUT:&P1_INPUT., which would correctly set the value of P3_OUTPUT and add an extra semi-colon between the session identifier and the arguments-values pair.