SimpleForm select to not include a blank (by default) - forms

To have a select box omit the blank option you can do:
:include_blank => false
In Formtastic, there's a config option that allows you to do this by default:
Formtastic::FormBuilder.include_blank_for_select_by_default = false
Is the a way to configure this in SimpleForm too? I haven't been able to find it in the docs or anything...

Sorry but you can't do this with Simple Form right now. There was a pull request adding this feature but it wasn't merged. If you want to add it to Simple Form pull request is more than welcome.

Related

TYPO3 extension: how to find certain TS setting

I found in typo3 admin side(/typo3), you can have two ways to set up TS,
you can set up through template->root, I think TS here will affect the whole site.
you can set up through template->certain page, it will only affect this page.
So my question is:
If I want to find where(which page) has TS setting such as : code = LIST, how could I do?
Use Web > Template module it has tools, you can for an example use Template Analyzer for the search
Try querying the database in phpMyAdmin or similar. The following looks in Template Setup:
SELECT pid, config, constants
FROM sys_template
WHERE config LIKE '%code = LIST%'
Replace config with constants to look in Template Constants. pid is the page ID.
If it is not set in the TypoScript, it perhaps has been set in the plugin itself. Just check the plugin content element itself.
In the Template module, go to the page where the setting is in effect.
Use the TSOB (Typo Script Object Browser) to search for "list":
This must show you all TS for this page that contains "list".
If you don't see the setting you can run a cmd/ctrl-F Search over the entire results.
You would have to search for "[code] = LIST".
Which will lead you to the following entry:
Hovering over the label will produce the above tooltip. Copy the line number.
Now change to the Template Analyzer. Here, you can click through all cascading templates and search for the line number:
This is definitely the line that sets that value.
From the "Template hierarchy" tree you will easily find the template that contains the setting.

Find CURRENTLY selected <option> with XPath

What's the correct XPath syntax to check if an option element is currently selected, or just to get the selected option element from a select element, on an open page with which the user, and JavaScript, may have interacted? Is this even possible with XPath, or does it lack the ability to look at DOM properties?
I can't find any documentation on this, and have (speculatively) tried:
//option[#selected=true]
//option[#selected="selected"]
//option[#selected]
but none of these work; they simply don't match any elements.
(In case it matters, I've tried this both using the $x function in the Chrome developer console, and using the find_elements_by_xpath method in Selenium for Python.)
Short answer: it's not possible.
Longer answer: XPath can look at HTML attributes, but it can't look at DOM properties. Selecting an <option> element in a <select> changes the selected property of the <option> to true, and also changes the value property of its parent <select> element, but it doesn't affect the attributes of either, so it is invisible to XPath.
To find <option> elements that have the selected attribute set, which is often how a page author might determine which option is initially selected, you can use //option[#selected]. But this does not find the currently selected <option>; changes that the user makes to the selection are invisible to XPath. There's no guarantee it will even find the initially selected option, since it's possible that the page author didn't put the selected attribute on any elements and either let the browser select the first option by default or had some JavaScript select the initial option via the selected property.
The multiple other answers here claiming that a selector like //option[#selected] can detect selection changes made by the user after the page loads are simply completely wrong.
Of course, if you're able to use CSS selectors instead of XPath selectors, then option:checked will do the job.
The problem could be the " (double quotes).
//select/option[#selected='selected'] - Will match the selected option, i am using this successfully.
//select/option[#selected='selected' and #value='specific value'] - Will only match the selected option if it has a 'specific value', i'm also using this.
If you are still having trouble, it could be an entirely different problem, perhaps there is no option node. I hope this helps.
I think we can use a knowledge from #Mark's answer and account that. Let's just find a node which HAS desired attribute:
tree.xpath('//select/option[#selected]/text()')[0].strip()
I tried "//option[#selected=''] and it has worked for me.
it is able to highlight the selected option within Page objects model.
I would try //option[#selected='true']
i.e. driver.findElements(By.xpath("//option[#selected='true']")).getText();

Line breaks in Zend Navigation Menu labels

I have a need to create a <br/> tag in the display label for a menu item generated using Zend_navigation, but don't seem to be able to find a way to do so.
My navigation item is defined in the XML config as:
<registermachine>
<label>Register your Slitter Rewinder</label>
<controller>service</controller>
<action>register</action>
<route>default</route>
</registermachine>
I want to force a tag in the output HTML between 'your' and 'slitter', such that it appears on two line as below:
Register your
Slitter Rewinder
However, I can't seem to do it. obviously using in the XML breaks parsing, and using html entities means that the lable is displayed as:
Register your <br/>Slitter Rewinder
Has anyone had experience of this that can offer advice?
Thanks in advance!
there is no such option built-in you have to use a partial
$partial = array('menu.phtml', 'default');
$this->navigation()->menu()->setPartial($partial);
echo $this->navigation()->menu()->render();
http://framework.zend.com/manual/en/zend.view.helpers.html#zend.view.helpers.initial.navigation.menu
you may also try a hack with <label><![CDATA[Menu label<br/>Second line]]></label>
I found a (hacky) solution:
I updated my navigation.xml to use {br} tokens wherever a <br/> tag is required, and then amended the base Zend/View/Helper/Navigation/Menu.php file as follows:
within htmlify function, changed
$this->view->escape($label)
to
str_replace("{br}", "<br/>", $label)
I could (and probably will) override the Zend Library Menu View Helper with my own at some point, but this at least cover it for now.
there is a escapeLabels boolean used to convert html tags and it's true by default.
You can set your navigation like this
$this->navigation()
->menu()
->escapeLabels(false)
->...
http://framework.zend.com/apidoc/2.0/classes/Zend.View.Helper.Navigation.Menu.html#escapeLabels

drupal Webform select list empty first value

I need for my select lists to have a default option of an empty value, or "Select" with no value.
I don't see any mention of how to do this in the documentation.
// $Id: webform.module,v 1.196.2.47 2010/08/16 17:54:19 quicksketch Exp $
You can add the patch webform_select_none_0.patch as mentioned in http://drupal.org/node/563170. Or if you do not have any experience with patches, you can add the following code to the _webform_render_select function in /sites/all/modules/webform/components/select.inc (of course taking into account any disadvantages of manually editing code)
if ($component['extra']['aslist'] && !$component['extra']['multiple'] && ($default_value === '' || !$component['mandatory'])) {
$element['#empty_value'] = '';
}
This will add the - Select - option to mandatory webform select fields when no option is selected
On the webform controls tab (node/%/edit/components/%), all you need to do is uncheck the "Mandatory" checkbox under "Advanced Settings".
Create a custom module and use form alter to modify the output. Explained here: https://www.drupal.org/node/1331956#comment-5876808
I believe you can achieve this with an empty entry in your option list:
|--Choose one--
val1|Value 1
val2|Value 2
val3|Value 3
etcetera.
However, I can't seem to find any sources on this at the moment. Good luck!

Creating Expandable Forms in Microsoft Access 2007

I need to gather some information from a Microsoft Access form and I need everything to be as organized as possible.
There are a lot of columns that can be filled out, but don't necessarily apply to everyone and I want to keep everything as clean as possible.
In a form, is there any way to have certain input boxes displayed only if the user says they have that information?
For example:
Do you have a dog? () yes (o) no
Do you have a dog? (o) yes () no.............Dog name: [_________________________]
The yes's/no's shouldn't be added to the database, but I can dump them somewhere if need be.
Thanks in advance!
Justian
P.S
I'd like to put this on SharePoint as well, so extra brownie points if you can run me through that as well real quick.
Thanks again!
The way I usually handle this is with an option group for the first question, and a disabled text box for the other information, inside the frame of the option group. In the AfterUpdate event of the option group, you set the enabled property of the textbox:
Me!txtDogName.Enabled = (Me!optHasADog = 1)
...assuming that the value of the YES choice is 1.
You'd likely want to set the default value of the option group to the NO choice, and then you'd have the name field disabled by default.
You would also need the OnCurrent event of your form to do the same thing as in the AfterUpdate event.