How to compare select options with database values? - ruby-on-rails-4

I have a class called State in my model and a states select (combo box) in my page. I need to create the step definition that compares the values in the database to the values in the combo box.
I've been able to find the combo box by its ID, but I couldn't find a way to compare each option.
expect(page.find_by_id('patient_state_id'))
How can I do this?

I've been able to solve this with the following code:
Given(/^I am an application user$/) do
end
When(/^I display the patient registration form$/) do
visit('/patients/new')
end
Then(/^I should be able see the list of registered states$/) do
states = State.pluck(:description)
page.find_by_id('patient_state_id').all('option').each do |el|
expect(states).to include(el.text)
end
end

Related

Pass values between pages in Oracle Apex

I am developing a mobile application that should allow a student to search for job vacancies. I have used the wizard to create a form with a list view. The list view will only show job titles which are not past their closing date (available jobs)
When a job title is clicked it redirects to the form where the student can view further job details. These values are passed automatically by the wizard.
Now while this whole thing is great I need information from 3 different tables and the wizard won't help me with that.
I have created a list view based on an sql query and also a form based on an sql query. I have tried to create automatic fetch processes to pass the values from my list view to the form view but nothing I have tried has worked. I carefully analysed the forms created by the wizard to see how it could be done but nothing worked for me and I would really love to do it in this way.
For reference this is the sql code I used for the list view (and it's the same for the form view except for the where clause )
T1.JOB_TITLE,
T1.SALARY,
T1.JOB_DESCRIPTION,
T1.START_DATE,
T1.CLOSING_DATE,
T1.METHOD_ID,
T3.METHOD_NAME,
T1.SITE_ID,
T2.CITY,
T2.ADDRESS_FIRST_LINE,
T2.EMAIL,
T2.COMPANY_NAME
FROM JOB T1
JOIN SITE T2 ON (T2.SITE_ID = T1.SITE_ID)
JOIN APPLICATION_METHOD T3 ON (T3.METHOD_ID = T1.METHOD_ID)
Where (T1.Closing_Date >(Select Current_Date from dual))
There are really two ways you could solve this:
1) If you can simply pass the values you need to the form page, edit the values of your Form region, and open up the "Link Target" attribute (this is assuming you're using APEX 5 Page Designer). There, you will be able to pass in multiple values to items on your Form page.
2) If, instead, you need to derive these values on your Form page, add an After Header process on your form page and do the lookups from your other tables in this process, using PL/SQL. You can use the bind variable syntax to reference your items and update session state. For example:
begin
for c1 in (select val1, val2 from my_other_table where id = :P3_ID) loop
:P3_ITEM1 := c1.val1;
:P3_ITEM2 := c1.val2;
exit;
end loop;
end;
I managed to add the additional columns by adding more items and selecting an Sql-query that returns a single row from the item attributes (Source).
So in order to get method_name rather than an ID which would be irrelevant for the end user I used this code:
SELECT METHOD_NAME FROM APPLICATION_METHOD
WHERE (METHOD_ID = :P3_METHOD_ID)
I am fairly certain that it might not be a great solution if you have a lot of columns that need to go through but it was easy to understand and implement for a few additional columns.

how to match a field name with another field name

I have two fields that run throughout a website that I would like to match so that when a user inputs a value either of the fields, it will match the other field. I'm using Sitecore Rocks and am trying to use a query to do this.
select ##h1#, ##Title#
from /sitecore/Content/Home//*[##h1# !="##Title#"];
update set ##h1# = ##Title# from /sitecore/Content/Home//*[##Title# = "<id>"];
What am I missing here?
This article talks about tapping in to the item:saving event which allows you to compare the fields values of the item before and after the changes:
http://www.sitecore.net/Community/Technical-Blogs/John-West-Sitecore-Blog/Posts/2010/11/Intercepting-Item-Updates-with-Sitecore.aspx
Using this, you can determine which field has been amended, then change the other to match.
I've had to do something similar to this when a new field was added, and we wanted to set the initial value equal to an existing field. It may be a bug in Sitecore Rocks, but I found it would only update a field when a static value was part of the query.
When I ran ##h1# = ##Title#, the query analyzer would return the correct number of items updated, but no values were actually updated. However, ##h1# = '<id>' worked perfectly. After trying a number of things, I found this did what I wanted.
update set ##h1# = '' + ##Title# from /sitecore/Content/Home//*[##Title# = "<id>"];
I hope that helps.

Get products according to chosen value

I am creating a shop with Opencart 1.5.6 & I'm new to opencart & php so please help me
I searched a lot but all of results are talking about adding a filter in SORT drop down list like manufacturer ..
but I don't want to sort,
I added a new custom field called COLOR to product and i want to create a new drop down list contains RED,BLUE,& BLACK options and it will get all the products with this chosen color.
I tried to create a drop down list like "Sort By:" one,
but i can't because i have no experience with PHP or Opencart.
PLEASE HELP ME !! and thanks in advance :)
As you said you are beginner so just go through step by step
In Opencart there is a feature called filter which exactly fulfills your requirement
**Step1 (Creating Filter)**
Admin panel>catalog>filter>Inset a new filter
->Filter Group Name "Color".
->click on add filter and add your colors "Red, Green, Blue...."
**Step2 (Adding Filter attribute to Product)**
Admin panel>catalog>products>edit product
->under the link tab there is a filter add the filter to product you want
eg if the product is red in color add "red"
->Do this to all product you wanted to be filtered.
**Step3 (Adding Filter Scope to category)**
Admin panel>catalog>categories>edit category
->under the data tab there is a filter add the filter you want to be displayed like "red, green etc.."
->Do this to all category you wanted filter to be displayed.
**Step4 (Enable Filter module or setting layout)**
Admin panel>Extensions>Modules
->Find Filter and click on install
->Now Edit the filter
->click on add module
->Set Layout to Category, Position to Content Top and Status to Enable
->Click on Save
Now you are done, In category you can see the filter feature in category,
If you still find difficulties you can follow the official documentation http://docs.opencart.com/display/opencart/Filters
Hope this helps.

Sitecore - Validate a drop list value change event

I have a sitecore item, "category", which has a drop link which populate "product type" template list.
Each category can have a "product type".
(Products being created under a category node will be using the template selected in the drop down. e.g. Shoes category will have a Shoes template, Slippers category will also have a shoes template, Bags category will have a bags template).
Problem:
These categories should be able to mark related categories. Therefore I need to show a treelist kind of a control which only allows options to select categories with same "product type".
Under "Shoes" category, I need to have "Slippers".
How can I do this?
After selecting "Slippers" as the related item to "Shoes", if the user tries to change the "product type" drop link value in "slippers", how can I warn the user that this product type has already linked to another category?
(Validation on saving the category item.)
Hope this is a common issue with Related items in Sitecore, yet I could not find a solution for this.
Your first problem, "marking related categories" is not clear to me what you want to achieve with it.
But if I understand you correctly, you want to select a product-type-template in the Category-item to let the editor create products of the chosen producttype below the Category-item.
You can resolve this by using the item:saved event on the Category-item:
- first check if you are saving an item of type Category but checking the template.
- If it is a Category-Item, read the value of the product-type droplink and on the fly add this template to the insert-option of the Category item.
Your second problem with the check on related items can merely handled the same way by using the item:saving event. Not the item:saved event because you want to do the check before the item is saved so you can cancel the saving and display a messagebox through the Sitecore.Web.UI.Sheer.SheerResponse.Alert() method.
In the item:saving event you need to check if the current item has 1 or more referrers (items that link to this item) through the LinkDatabase method Globals.LinkDatabase.GetReferrers().
Using validation on this instead of the item:saving event is not usefull because the validation event only throws a warning and saves the item anyway.
Another good link with example code is this blog of John West.

How can I check that an item already exists in a SharePoint list?

I wish to create an event receiver that, when adding an item through an InfoPath form from one list to another, it will not create a new item if the item already exists, it will just update the 'quantity' of that item.
Eg.
Stock Items List > Add 2 Milk to Cart > Milk is already in Cart > Updates Milk to Quantity of 3.
You should have a unique key to identify your item. Ideally this would be a number or something like that, so you can identify the item in the second list. In your example with the milk, you don't have an ID. So you could add one or you could just compare the item with the text (I suppose "Milk" will be in the title field)
When the item is being added in the list you can then in the "ItemAdding" check with an SPQuery if the item already exists in the list (enough examples to find online). If query returns 0 items, you can just let SharePoint do it's work as it normally should. If an item is found you should then update the quantity of the found item.
2 remarks you should take into account:
To avoid that the item is being added when it already is in the list you can use following code.
properties.Cancel = true;
properties.Status = SPEventReceiverStatus.CancelNoError
The cancel makes sure that the item is not being added. Normally this throws an error but by setting the status no error is thown.
The second thing you should take into account is if you want to let the item update fire on updating the quantity. Because this can cause strange behavior. I would recommend disabling event firing before updating the quantity and then enable it again.