How does one simply submit an html form via dart? - dom

This is how one might do it in javascript: document.getElementById("myForm").submit();
How does one do it with dart?

Try to check type of element:
Element form = querySelector("#myForm");
if(form is FormElement){
form.submit();
}
If it doesn't work, try to use iterop. It will be something like this: content("document").call("getElementById",["myForm"]).call("submit",[]);

Related

Get back the webdriver.Locator out of an elementFinder

Given I have the elmFinder variable:
var elmFinder = element(by.css('.thing'));
What if i need to get back the webdriver.Locator, a.k.a locator strategy? i.e.
elmFinder.??? //=> by.css('.thing')
I'm looking after the function ??? if it exists.
UPDATE:
This feature has been merged and we can now do:
elmFinder.locator();
UPDATE:
This feature has been merged and we can now do:
elmFinder.locator();
Old answer:
You cannot. The element finder does not keep a reference to the locator:
https://github.com/angular/protractor/blob/master/lib/protractor.js#L103
What I typically do is store the selector in it's own var, and then place that string into the selector, so I can use both interchangably:
var cssThingSelector = '.thing';
var elem = $(cssThingSelector);
Something like that.
Edit:
I will also add that you can nest findElement calls from selenium webelement objects.
So, if there is another item in the inner html of the .thing web element (say, a span tag), you could just nest another findElement call:
var spanElem = elem.$('span');
You can do this as much as you'd like.

Check any errors in Zend Form text input

When i submit a form of Zend Framework 2, i would like to check in each single input has any errors, and if so, do something in the view.
Is there any "hasError()" (of the single input element) method?
For the Form, there is the "isValid()" method.
Thanks
Use getMessages() and check if variable is empty.
foreach ($form as $element) {
$messages = $element->getMessages();
if (!empty($messages)) {
// do something
}
}

Grab JSPX user input directly from a trinidad UIXComponent in my Java code?

I would like to retrieve the user input from a component within my Java code. Something akin to textbox.text in aspx/.NET. I am finding the documentation very confusing and my attempts don't compile. Is there a way?
<tr:inputDate id="date" required="true"
inlineStyle="color:rgb(0,58,117); font-weight:bold;"
value="#{processScope.benefit.serviceDate}"
immediate="false"
onchange="submit();"
label="#{mb_ResourceBean.res['claim.serviceDate.label']}">
<tr:convertDateTime pattern="yyyy/MM/dd" secondaryPattern="yyyyMMdd"
type="date"/>
<tr:validateDateTimeRange minimum="#{bk_ClaimBean.minDate}"
maximum="#{bk_ClaimBean.maxDate}"/>
</tr:inputDate>
Poor half-attempt to grab input:
UIViewRoot viewRoot = FacesContext.getCurrentInstance().getViewRoot();
UIXComponent component = viewRoot.findComponent("date"); //does not compile
I'm not sure what you are trying to achieve, but since you already have a value binding (#{processScope.benefit.serviceDate}) and you have onchange="submit();" in your <tr:inputDate> it looks like you want to use a valueChangeListener.
You need a method to handle the value change event in your bean, for example:
public void dateChanged(ValueChangeEvent event)
{
System.out.println("New value: "+ event.getNewValue());
System.out.println("instanceof Date: "+ (event.getNewValue() instanceof Date));
}
In your jspx you have to add the listener. Also you might want to use autoSubmit="true" instead of onchange="submit();", for example:
<tr:inputDate value="#{myBean.myDate}"
valueChangeListener="#{myBean.dateChanged}"
immediate="true" autoSubmit="true"/>
The code in your question does not compile since viewRoot.findComponent() will return a UIComponent. You need to cast it to UIXComponent.
Also, you need to take the naming containers into account. You will need to use something like: viewRoot.findComponent("formId:date");. In this case formId is the id of your <tr:form>.

Zend: Quick and succinct way of inserting custom HTML into a Zend_Form?

Is there some method that accepts inserting custom html without having to actually add form controls, even if they're hidden and making my html a decorator?
I'm looking for something like:
$this->addCustomElement( array(
'div',
'body' => '<p>inner text</p>'
) );
I need something short and quick, I don't want to create a new class or something overkill.
Well it's really as simple as this:
$note = new Zend_Form_Element('note');
$note->helper = 'formNote';
$note->setValue('<b>hi</b>');
$form->addElement($note);
But the problem is that when you submit the form, the form calls $note->isValid(), which overrides the value, so if there are errors with the form, the next time you display it, the custom HTML won't be shown. There are two easy ways to fix this, the first is to override isValid() in your Form class like this:
public function isValid($data)
{
$note = $this->note->getValue();
$valid = parent::isValid($data);
$this->note->setValue($note);
return $valid;
}
But personally I find this kinda hackish way, and prefer the second option. That is to write a very simple class (this should really be part of Zend itself, I have no idea why it isn't, since it includes a formNote view helper, but no element that uses it):
class My_Form_Element_Note extends Zend_Form_Element_Xhtml
{
public $helper = 'formNote';
public function isValid($value, $context = null) { return true; }
}
Then you just have to do:
$note = new My_Form_Element_Note('note');
$note->setValue('<b>hi</b>');
$form->addElement($note);
And everything will just work.
Other options include doing some black magic with decorators, but I really recommend you to not go down that path.
Also note the AnyMarkup Decorator.

Zend Avoid submit button value in GET parameters in url

I have a form, created with Zend_Form, with method = GET used for searching records with elements as below:
[form]
user name [input type="text" name="uname"]
[input type="submit" value="Search" name="search"]
[/form]
After form is submitted all the GET parameters along with submit button value are appearing in the url.
http://mysite.com/users/search?uname=abc&search=Search
How to avoid submit button value appearing in the url? is custom routing the solution ?
When you create your element, you can simply remove the name attribute that was automatically set at creation
$submit = new Zend_Form_Element_Submit('search')->setAttrib('name', '');
Or inside a Zend_Form
// Input element
$submit = $this->createElement('submit', 'search')->setAttrib('name', '');
// Or Button element
$submit = $this->createElement('button', 'search')->setAttribs(array
(
'name' => '', 'type' => 'submit',
);
When a form gets submitted, all of its elements with their names and values become a part of a GET / POST - query.
So, if you don't want an element to appear in your GET - query, all you need to do is to create this element without a name. That's probably not the best approach, but since we're talking about the 'submit' element, I guess it doesn't matter that much.
Looking at Zend_View_Helper_FormSubmit helper, you can see that it's creating the 'submit' element and setting its name. So, the possible solution would be to create your own view helper and use it for rendering the 'submit' element instead of the default helper.
You can set a custom helper with
$element->setAttribs( array('helper' => 'My_Helper_FormSubmit') );
Then build your own form element class and remove the name attribute from the element with preg_replace. The beauty of it is, it will not interfere with the other decorators.
So the something like this:
class My_Button extends Zend_Form_Element_Submit
{
public function render()
{
return preg_replace('/(<input.*?)( name="[^"]*")([^>]*>)/', "$1$3", parent::render(), 1);
}
}
You can remove name attribute for submit button in javascript.
jQuery example:
$('input[name="submit"]').removeAttr('name');
In the controller that represents the form's action, redirect to another (or the same controller) only including the relevant params.
Pseudocode:
$params = $this->getRequest()->getParams();
if isset($params['search'])
unset($params['search']);
return $this->_helper->Redirector->setGotoSimple('thisAction', null, null, $params);
handle form here
This is basically the same idea as Post/Redirect/Get except that you want to modify the request (by unsetting a parameter) in between the different stages, instead of doing something persistent (the images on that Wiki-page shows inserting data into a database).
If I were you, I would leave it in. IMO it's not worth an extra request to the webserver.