ToscaWidgets - customize form - turbogears2

I'm using https://pypi.python.org/pypi/tgapp-resetpassword/0.1.5 which allows you to override the template used for the reset password page. Unfortunately, the actual form itself is included as a 'black box':
<div>
${reset_password_form.display(action=action)}
</div>
The form has been defined as a tw2.forms.TableForm which is not how I'd like to display it. Is it possible to have finer grain control e.g. insert custom html around each of the fields, or be more explicit about how to display certain fields?
E.g. I'd like to do something like the following (made up):
<div>
<form ${reset_password_form.attrs} class="my-own-class-name">
<py:for each="field in reset_password_form.fields">
<div class="custom-class-here">
<label for="${field.id}">
... some logic to possibly override default label else...
${field.default_label_text}
</label>
${field.render_as_input_field()}
</div>
</py:for>
<button type="submit">My own submit text</button>
<form>
</div>
Is this level of customization possible with ToscaWidgets without overriding things in Python?

As by resetpassword documentation you have a reset_password.reset_password_form option that can be used to specify an alternative tw2 form.
You just need to put there the python path (like "resetpassword.lib.forms.ResetPasswordForm") of the form you would like to use in place of the default form.
Then you own form can specify a custom template like https://gist.github.com/amol-/d2a08027d34a8c4dfa69

Related

Reusable templates and methods?

I wish to wrap different types of input with a label and an error message, so far I have come up with this solution, using slots:
Input Text Component: (but there are also others for select, checkbox etc)
<form-input>
<input type="text" #click="doSomething"> //could be select, checkboxes etc. slotted in
</form-input>
Generic Form Input Component:
<div>
<label v-text="label"></label>
<slot></slot> //where each input is placed
<p v-if="hasError">This {{ this.name }} has an error!</p>
</div>
On Input Text Component I also use a mixin that handles all the errors and other form bits, I need to declare this in every different input type, select, checkbox etc.
Is there an easier way to achieve this, I want to:
Wrap various inputs with errors and labels.
Use the same functionality from a mixin (or declared as something else) for every component but not repeat the declaration - I cannot add it on the generic form input component as it is referenced in the data in the parent to be slotted in.

Splinter Is it possible to use browser.fill without name as a query

I would like to use an absolute xpath to fill in a search bar. The ids and classes are dynamically generated and there is no name variable or instance. So it feels like I'm stuck without a tool to fill in boxes without the named variable.
Is there a way around this? Can I somehow change the absolute xpath to look like its a name assignment and then query and fill based on the new 'type' I assigned the absolute xpath?
Is there a method for this in Selenium if not available in Splinter?
I've select by CSS and I'm finding this error 'selenium.common.exceptions.InvalidElementStateException: Message: Element is not currently interactable and may not be manipulated'
Edit:
<div class="type-ahead-input-container" role="search">
<div class="type-ahead-input-wrapper">
<div class="type-ahead-input">
<label class="visually-hidden" for="a11y-ember10393">
Search
</label>
<!---->
<input id="a11y-ember10393" class="ember-text-field ember-view" aria-
autocomplete="list" autocomplete="off" spellcheck="false"
placeholder="Search" autocorrect="off" autocapitalize="off" role="combobox"
aria-expanded="true" aria-owns="ember11064" data-artdeco-is-focused="true"/>
<div class="type-ahead-input-icons">
<!---->
</div>
</div>
<!---->
</div>
</div>
As you have asked Is there a method for this in Selenium, the Answer is Yes.
Selenium supports Sikuli. Sikuli automates anything you see on the screen. It uses image recognition to identify and control GUI components. It is useful when there is no easy access to a GUI's internal or source code.
You can find more about Sikuli here.
Let me know if this answers your question.
When you get an error-message like that, it could be that your search result is not what you expected. It could be that you are getting more than one result, ie a list. On a list you can not input.
You can find the input boxes with an xpath, select the prefered one from the list (by trying) and put a text in it with the WebDriverElement _set_value method. That is not appropriate because of the _, but it is usefull.
input_list = browser.find_by_xpath('//div[#class="type-ahead-input"]/input[#class="ember-textfield ember-view"]')
input_list[1]._set_value('just a text to see whether it is working')

Selenium access a form field with bad id

Looking for the best approach to enter / read a value from a form field that lacks human readable ids / references.
The basic outline looks like
<div id="form-2143">
<div id="numberfield-1234">
<label id="numberfield-1234-label">
<span class="x-form-label">Field Name 1</span>
</label>
<div id="numberfield-1234-body">
<div id="numberfield-1234-wrap">
<input id="numberfield-1234-input" class="form-field" componentid="numberfield-1234">
</div>
</div>
</div>
...
</div>
There are more class defs and attributes involved, but above is the "basics" I have to work with.
This form has a number of entries, and there are more forms like it, so I am looking for a way to search for the label name, and access the input field within the same container.
I lack control of the site and cannot edit the HTML structure of the site; meaning I cannot give sensible names to the ids, but want to avoid hard referencing the poor names. Any suggestions on how to get Robot Framework & selenium to reference these elements?
Highlighting Andersson's answer in the comments
Using the XPath
//label[span[text()="Field Name 1"]]/following-sibling::div//input
Works for the above example.
The key part that answers the question of how to reference nearby elements is
/following-sibling

How to populate a webform variable

I'm attempting to use VB.Net WebBorwser to populate and submit a webform. I'm using webbrowser because I don't know much javascript or c#. I'm open to other ideas of course.
I'm able to populate the form fields easily enough:
m_oWebBrowser1.Document.GetElementById("line1").SetAttribute("value", "Flat 12")
but this isn't enough to trigger the page to set the require variables. I've also tried:
m_oWebBrowser.Document.GetElementById("line1").InvokeMember("change")
and
m_oWebBrowser.Navigate("javascript: PreviousAddress().Address().Line1='Flat 19';")
The input field looks like this:
<input id="previousAddressLine1" class="col-xs-12 col-sm-8" name="previousAddressLine1" tabindex="12" data-bind="value: PreviousAddress().Address().Line1" type="text">
Any help would be great.
-Ben

How to get an article description or excerpt within Expression Engine

I saw in Expression Engine I can use {embed:title} and {site_name} variables, but now I need a variable to pull an excerpt or description of the article itself. Is there such a variable/tag?
ExpressionEngine tags are based solely on custom fields which you yourself have defined. So in the field group for your "articles" channel, you'll have some fields, maybe {article_summary}, {article_body}, {article_image}, etc. To display your summary, just use {article_summary} in your template.
I'm assuming that you're coming from something like WordPress maybe, where every piece of content has the_content() and the_excerpt() ... aside from a handful of global variables, and some fields which are universal to all entries (like {title}, {entry_date}, etc), ExpressionEngine isn't like that. You define what fields you use for each channel - you have complete control.
Here is the actual code you have to include in your EE template.
{exp:channel:entries channel="article" limit="5" dynamic="no"}
<div class="home_thumb">
<h1>{title}</h1>
<div class="home_thumb_img">
<img src="{article_image}">
{if article_content}
<p>{article_content}</p>
{/if}
</div>
</div>
{/exp:channel:entries}