How to use hamlet template with route parameter? - forms

I'm working on a yesod app based on the yesod-postgres stack template. I have a route defined in config/routes that has the form:
foo/edit/#Text EditFooR GET
In my hamlet template, I want to write
<form method=post action=#{EditFooR}#forms enctype=#{formEnctype}>
^{formWidget}
<button type="submit">
Submit
and in my Handler I'd like to write:
getEditFooR :: T.Text -> Handler Html
getEditFooR name = do
....
text <- findTextByName name
(formWidget, formEnctype) <- generateFormPost (editFooForm text)
defaultLayout $ do
$(widgetFile "editFoo")
Except that I need to provide the parameter to the #{EditFooR} route. How is this done in the Hamlet file/Handler?

The answer is that the .hamlet template should have the format:
<form method=post action=#{EditFooR fooName}#forms enctype=#{formEnctype}>
^{formWidget}
<button type="submit">
Submit
and the Handler should have the format:
getEditFooR :: T.Text -> Handler Html
getEditFooR name = do
....
text <- findTextByName name
fooName <- "something or other"
(formWidget, formEnctype) <- generateFormPost (editFooForm text)
defaultLayout $ do
$(widgetFile "editFoo")

Related

How do I pass Variants as props to React Components in ReasonML?

I have tried the following approach to be able to send variants as props.
type ipAddr =
| IPV4
| IPV8;
[#react.component]
let make = () => {
let appData = Data.tileData;
<div className="App">
<header className="flex outline justify-between" />
<Content selected={ipAddr.IPV4} appData />
</div>;
};
But it throws the error,
ninja: error: rebuilding 'build.ninja': subcommand failed
I have tried sending variants directly to Component as well.
<div className="App">
<header className="flex outline justify-between" />
<Content selected=IPV4 appData />
</div>;
But it ended up returning another error
Start compiling ninja: error: dependency cycle: src/App-ReactHooksTemplate.cmj -> src/Content-ReactHooksTemplate.cmj
-> src/App-ReactHooksTemplate.cmj
Finish compiling(exit: 1)
Where am I going wrong?
DISCLAIMER: I don't know ReasonML, however
If it was OCaml, you'd just write IPV4, no need to qualify it like ipAddr.IPV4.
Perhaps this is the same in Reason?
I have solved this another way. Instead of passing the variant as prop, I simply rendered different components based on variant value.
[#react.component]
let make = () => {
let appData = Data.tileData;
switch (selected) {
| IPV4 =>
<div>
<IPV4Renderer appData />
</div>
| IPV6 =>
<div>
<IPV6Renderer appData />
</div>
};
};

Protractor css locator for md-select

I'm new to protractor and need to know how can i get the text i.e. Connections in the below code block. I need to click this "Connections". Anyhelp would be really appreciated. Thanks in advance
<md-option ng-repeat="worksite in vmSplashController.worksites track by $index" id="option_worksite_TRANSFER" ng-value="worksite" tabindex="0" class="ng-scope" role="option" aria-selected="false" value="[object Object]">
<div class="md-text ng-binding">
Connections
</div>
</md-option>
Full code
<md-dialog ng-cloak aria-span="" id="splashDialog" class="asui-popup-container splashContainer">
<form name="splash">
<md-dialog-content class="agentDetails" flex>
</md-dialog-content>
<md-dialog-content class="agentOptions" flex layout="row">
<md-input-container class="md-input-has-placeholder" id="nav_worksite" ng-if="vmSplashController.worksites.length >= 1" flex="50" layout="column">
<label class="select-lable">Worksite</label>
<md-select md-no-ink name="nav_worksite" required ng-model="vmSplashController.worksites.selected" ng-model-options="{trackBy: '$value.locationCode'}" aria-label="Select Worksite" md-container-class="md-select-custom nav-worksite-selectbox" ng-change="vmSplashController.onWorksiteChange(vmSplashController.worksites.selected)">
<md-option ng-repeat="worksite in vmSplashController.worksites track by $index" id="option_worksite_{{worksite.locationCode}}" ng-value="worksite">
{{**Here that Div is being created i.e. Connections along with other two options**}}
</md-option>
</md-select>
</md-input-container>
</md-dialog-content>
<md-dialog-actions layout="row">
<md-button md-no-ink class="md-primary nobg-btn" ng-click="vmSplashController.onConfirm()" ng-disabled="splash.$invalid">
CONFIRM
</md-button>
</md-dialog-actions>
</form>
</md-dialog>
I treid this
element(by.cssContainingText('.option_worksite_TRANSFER > div.md-text', 'Connections')).click();
but getting the below error.
Message:
Failed: No element found using locator: by.cssContainingText(".option_worksite_TRANSFER > div.md-text", "Connections")
First - I'm a bit confused. In example you are trying to select class option_worksite_TRANSFER, but in error message it has an id.
If you are trying to select value from dropdown, try this solution:
https://stackoverflow.com/a/39047319/6331748
Try this using xpath:
element(by.xpath("//div[text()='Connections']")).click();
Try using the below code:
element(by.cssContainingText('[id^="option_worksite"] > div.md-text', 'Connections')).click();
Adding waits:
var EC = protractor.ExpectedConditions;
var ele = element(by.cssContainingText('[id^="option_worksite"] > div.md-text', 'Connections'));
browser.wait(EC.visibilityOf(ele), 5000).then(function(){
ele.click();
});

Golang - ParseForm ; err = mime: expected slash after first token

Am getting this Error = mime: expected slash after first token
Some details below.
The goal is a login form that the username and password
can be extracted from the POST.
I also tested a curl post and a static html form --> same issue = mime: expected slash after first token
Snippet of the go code:
log.Printf("\n\n\t[loginH()] - POST method ...\n")
err := r.ParseForm()
if err != nil {
// Handle error here via logging and then return
DebugLog.Printf("[loginH()] - ERROR: with r.ParseForm. (err=%v)\n", err)
log.Printf("[loginH()] - ERROR: with r.ParseForm. (err=%v)\n", err)
}
username := r.Form["username"]
passwd := r.Form["passwd"]
log.Printf("[loginH()] - r.Form ... username=%s and passwd=%s\n",username,passwd)
The html/form is:
<form method="POST" action="/login">
<input type="text" name="username" placeholder="Email Address"/>
<input type="password" name="passwd" placeholder="Password"/>
<input type="submit" id="loginBtn" name="login" value="Logon"/>
</form>
Output is:
2016/12/15 21:36:07 [loginH()] - POST method ...
2016/12/15 21:36:07 [loginH()] - ERROR: with r.ParseForm. (err=mime: expected slash after first token)
2016/12/15 21:36:07 [loginH()] - r.Form ... username= and passwd=
Thanks in advance for any pointers/information/enlightenment.
r.Form is empty
This error comes from line 85 of mediatype.go. You're probably getting this error from a call to ParseMediaType method internally. From there it seems like your static form or curl is not setting some value of Content-Type or Content-Disposition correctly. Please check these headers for any problematic values.
From docs:
// ParseMediaType parses a media type value and any optional
// parameters, per RFC 1521. Media types are the values in
// Content-Type and Content-Disposition headers (RFC 2183).
// On success, ParseMediaType returns the media type converted
// to lowercase and trimmed of white space and a non-nil map.
// The returned map, params, maps from the lowercase
// attribute to the attribute value with its case preserved.

Capybara choose method Unable to find radio button

I have a form which is generated by simple form:
TL TR
<div class="form-group radio_buttons required user_register_temp_package">
<label class="radio_buttons required control-label">
<abbr title="zorunlu">
*
</abbr>
Paket
</label>
<label class="radio">
<input class="radio_buttons required" id="user_register_temp_attributes_domain_package_id_1" name="user[register_temp_attributes][domain_package_id]" type="radio" value="1">
Small
</label>
<label class="radio">
<input checked="checked" class="radio_buttons required" id="user_register_temp_attributes_domain_package_id_2" name="user[register_temp_attributes][domain_package_id]" type="radio" value="2">
Medium
</label>
<label class="radio">
<input class="radio_buttons required" id="user_register_temp_attributes_domain_package_id_3" name="user[register_temp_attributes][domain_package_id]" type="radio" value="3">
Large
</label>
</div>
TL TR
I have a simple spec like this:
# encoding: UTF-8
require 'spec_helper'
feature 'Register' do
background do
visit new_user_registration_path
end
scenario 'fill register form and register' do
# TL TR
choose('user_register_temp_attributes_domain_package_id_1')
# TL TR
end
end
My spec_helper.rb is
ENV['RAILS_ENV'] ||= 'test'
require File
.expand_path('../../config/environment', __FILE__)
require 'rspec/rails'
require 'rspec/autorun'
require 'capybara/rspec'
Capybara.javascript_driver = :webkit
Capybara.default_selector = :css
Dir[Rails.root.join('spec/support/**/*.rb')].each { |f| require f }
ActiveRecord::Migration.check_pending! if defined?(ActiveRecord::Migration)
RSpec.configure do |config|
# ## Mock Framework
#
# If you prefer to use mocha, flexmock or RR, uncomment the appropriate line:
#
# config.mock_with :mocha
# config.mock_with :flexmock
# config.mock_with :rr
# Remove this line if you're not using ActiveRecord or ActiveRecord fixtures
config.fixture_path = "#{::Rails.root}/spec/fixtures"
# If you're not using ActiveRecord, or you'd prefer not to run each of your
# examples within a transaction, remove the following line or assign false
# instead of true.
config.use_transactional_fixtures = true
# If true, the base class of anonymous controllers will be inferred
# automatically. This will be the default behavior in future versions of
# rspec-rails.
config.infer_base_class_for_anonymous_controllers = false
# Run specs in random order to surface order dependencies. If you find an
# order dependency and want to debug it, you can fix the order by providing
# the seed, which is printed after each run.
# --seed 1234
config.order = 'random'
# Capybara DSL
config.include Capybara::DSL
# Factory girl
config.include FactoryGirl::Syntax::Methods
end
The Capybara API for the choose method says:
"Find a radio button and mark it as checked. The radio button can be found via name, id or label text."
But when I run spec with choose('user_register_temp_attributes_domain_package_id_1'), I get
Capybara::ElementNotFound: Unable to find radio button "user_register_temp_attributes_domain_package_id_1"
I've tried code below but got Capybara::ElementNotFound: Unable to find css "user_register_temp_attributes_domain_package_id_1" error:
find('#user_register_temp_attributes_domain_package_id_1[value=1]').set(true)
It seems there is no problem with fill_in, check or click_button methods.
Regards.
Most likely underlying driver thinks that this radio button is invisible. By default Capybara finds only visible elements (as Capybara.ignore_hidden_elements is true by default) so it didn't find that element.
Try:
choose('user_register_temp_attributes_domain_package_id_1', visible: false)
You can improve error message by submitting a pull request to Capybara.

lift net.liftweb.http.S#param doesnt works like wiki says

i try to copying the examples in wiki
http://wiki.liftweb.net/index.php/Hello_Darwin
in the example of HelloForm2.scala
"submit" -> submit(?("Send"), () => {println("value:" + who + " :: " + param("whoField"))}),
It always prints
value:Full(hogehoge) :: Empty" even if i set the who as "object who extends RequestVar(Full("world"))
am i do something wrong?
sorry for forgetting to post full code, i already try the second one in the wiki like below.
index.html
<lift:surround with="default" at="content">
<h2>Welcome to your project!</h2>
<lift:HelloWorld.show form="POST">
Hello <hello:who />
<br />
<label for="whoField">Who :</label>
<hello:whoField />
<hello:submit />
</lift:HelloWorld.show>
</lift:surround>
and HelloWorld.scala
class HelloWorld {
object who extends RequestVar(Full("world"));
def show(xhtml: NodeSeq): NodeSeq ={
bind("hello", xhtml,
"whoField" -> text(who.openOr(""), v => who(Full(v))) % ("size" -> "10") % ("id" -> "whoField"),
"submit" -> submit(?("Send"), () => {println("value:" + who.openOr("") + " :: " + param("whoField"))}),
"who" -> who.openOr("")
)
}
}
now, the who shows correct in the rendered page, but console still prints
value:hogehoge :: Empty
im using lift 1.0
thanks.
You have to change that code too, as shown in the example in the wiki page, which I'll copy here:
bind("hello", xhtml,
"whoField" -> text(who.openOr(""), v => who(Full(v))) % ("size" -> "10") % ("id" -> "whoField"),
"submit" -> submit(?("Send"), () => {println("value:" + who.openOr("") + " :: " + param("whoField"))}),
"who" -> who.openOr("")
)
Note that whoField is defined very differently.