Missing string after space erb - ruby-on-rails

I have used html.erb template in Rails to passing some value for HTML input and my source code looks like this:
<% all = "All value" %>
<input type="text" name="name" id="name" value=<%= all %>>
But when the view is rendered, it seems like a string after space was missing and I just got:
<input type="text" name="name" id="name" value="All">
But my expection is:
<input type="text" name="name" id="name" value="All value">
I appreciate any help!

Quote your all variable like this:
<input type="text" name="name" id="name" value="<%= all %>">

Related

Whether it is possible hide 'checkbox' with use th:unless?

I have a color filter, simillar to this:
<input type="checkbox" id="orange" class="orange" value="orange"/>orange
<br/>
<input type="checkbox" id="peach" value="peach"/>peach
<br/>
<input type="checkbox" id="terracotta" value="terracotta"/>terracotta
<br/>
<input type="checkbox" id="coffee" value="coffee"/>coffee
<br/>
<input type="checkbox" id="browne" value="browne"/>browne
<br/>
<input type="checkbox" id="rose" value="rose"/>rose
<br/>
<input type="checkbox" id="red" value="red"/>red
<br/>
I recive color from DB.
<div th:each="model : ${allColor}">
<span th:text="${model.color}"/>
Can I hide color, with use Thymeleaf, which is not in DB?
For example now I haven't Rose, Coffee and Peach colors, but maybe in future I will have this color. I want to do colors verification , if color is in DB, user can see on UI checkbox, else checkbox hide. I read about th:if and th:unless. Whether it is possible to make it with use Thymeleaf?
If I try to do:
<input type="checkbox" th:if="${model.color==coffee}"id="coffee" value="coffee"/>coffee
It's not working.
Instead of hiding colors, you should create the color checkboxes with a loop as well. Like this:
<th:block th:each="model : ${allColor}" th:with="color=${model.color}">
<input type="checkbox" th:id="${color}" th:class="${color}" th:value="${color}"/> <span th:text="${color}" />
<br />
</th:block>
As for why your original attempt didn't work, it's hard to tell without seeing more of the html. I'm guessing that ${model.color} was undefined, because you weren't in a loop? Also, you were missing quotes around 'coffee'. like this: `${model.color == 'coffee'
Something like this may work as well, but I would recommend the loop.
<input th:if="${allColor.contains('orange')}" type="checkbox" id="orange" class="orange" value="orange"/>orange<br/>
<input th:if="${allColor.contains('peach')}" type="checkbox" id="peach" value="peach"/>peach<br/>
<input th:if="${allColor.contains('terracotta')}" type="checkbox" id="terracotta" value="terracotta"/>terracotta<br/>
<input th:if="${allColor.contains('coffee')}" type="checkbox" id="coffee" value="coffee"/>coffee<br/>
<input th:if="${allColor.contains('browne')}" type="checkbox" id="browne" value="browne"/>browne<br/>
<input th:if="${allColor.contains('rose')}" type="checkbox" id="rose" value="rose"/>rose<br/>
<input th:if="${allColor.contains('red')}" type="checkbox" id="red" value="red"/>red<br/>}`.

Prevent user to type in a textbox [duplicate]

what is the code to disable an INPUT text box for HTML?
Thanks
<input type="text" disabled="disabled" />
See the W3C HTML Specification on the input tag for more information.
<input type="text" required="true" value="" readonly="true">
This will make a text box in readonly mode, might be helpful in generating passwords and datepickers.
The syntax to disable an HTML input is as follows:
<input type="text" id="input_id" DISABLED />
You can Use both disabled or readonly attribute of input . Using disable attribute will omit that value at form submit, so if you want that values at submit event make them readonly instead of disable.
<input type="text" readonly>
or
<input type="text" disabled>
<input type="text" required="true" value="" readonly>
Not the.
<input type="text" required="true" value="" readonly="true">

Sending POST with groovy to payment gateway

I have already found similar topics but my code doesn't work.
I need to connect a webshop with payment gateway.
Data must be sent with POST. The problem is that when I want to open the payment form, I get only the info web page about the payment gateway.
Here are parts of my code:
cart.gsp
<jq:jquery>
$("#buy").click(function(e) {
$.ajax({
type:'POST',
url:'${createLink(action: 'fetchPaymentForm')}',
success:function(data,textStatus) {},
error:function(XMLHttpRequest,textStatus,errorThrown) {}
});
e.preventDefault()
})
</jq:jquery>
This part of code runs when I click on button with id "buy".
shoppingCartController.groovy
version
def fetchPaymentForm(){
def restClient = new RESTClient("https://test.payment.com/redirect/")
def resp = restClient.post(
body: [target: "_top", mode: "form",
store_id:"${storeID}", orderNumber: "${orderNumber}",
language: "${language}", currency: "${currency}",
amount: "${amountAll}", cart: "${cart}", Hash:"${hash}", require_complete: "true"],
requestContentType: URLENC
)
}
version
def fetchPaymentForm(){
render(template: "/layouts/paymentForm", model: [orderNumber: orderNumber, amount: amountAll, currency: currency, language: language, storeID: storeID, cart: cart, hash: hash])
}
_paymentForm.gsp
<form method="POST" action="https://test.payment.com/redirect/" name="form" id="form">
<input id="target" name="target" value="_top" type="hidden">
<input id="mode" name="mode" value="form" type="hidden">
<input id="store_id" name="store_id" value="${storeID}" type="hidden">
<input id="order_number" name="order_number" value="${orderNumber}" type="hidden">
<input id="language" name="language" value="${language}" type="hidden">
<input id="currency" name="currency" value="${currency}" type="hidden">
<input id="amount" name="amount" value="${amount}" type="hidden">
<input id="cart" name="cart" value="${cart}" type="hidden">
<input id="Hash" name="Hash" value="${hash}" type="hidden">
<input id="require_complete" name="require_complete" value="false" type="hidden">
</form>
I would be very thankfull if someone could give me an advice or hint what to try.
EDIT:
Here is an example for redirect for C# which is shown in pdf file for payment implementation.
<input id="target" ClientIDMode="Static" name="target" value="_top" hidden="true"/>
<input id="mode" ClientIDMode="Static" name="mode" value="<%=mode %>" hidden="true"/>
<input id="store_id" ClientIDMode="Static" name="store_id" value=" <%=store_id %>" hidden="true"/>
<input id="require_complete" ClientIDMode="Static" name="require_complete" value="<%=require_complete %>" hidden="true"/>
<input id="order_number" ClientIDMode="Static" name="order_number" value="<%=order_number %>" hidden="true"/>
<input id="amount" ClientIDMode="Static" name="amount" value="<%=amount %>" hidden="true"/>
<input id="hash" ClientIDMode="Static" name="hash" value="<%=hash %>" hidden="true"/>
<input id="currency" ClientIDMode="Static" name="currency" value=" <%=currency %>" hidden="true"/>
<input id="cart" ClientIDMode="Static" name="cart" value="<%=cart %>" hidden="true"/>
<input id="payment_number" ClientIDMode="Static" name="payment_number" value="<%=payment_number %>" hidden="true"/>
<input id="language" ClientIDMode="Static" name="language" value="<%=language %>" hidden="true"/>
<asp:button id="Button2" Text="testcps"
PostBackUrl="https://test.payment.com/redirect/" runat="Server" ClientIDMode="Static" OnClick="Button1_Click" />
Obviously I'm missing something but I don't know what.
Thanks for tips in advance.

Why does "<input id='id' type=text name='id' value='H123'>" not get "POST"ed by FormData

When I submit the following form
<form name="fileUpload" id="fileUpload" method="post" action="javascript:void(0);" enctype="multipart/form-data">
<input id='id' type=text name='id' value='H123'>
<div class="file_browser">
<input type="file" name="multiple_files[]" id="_multiple_files" class="hide_broswe" multiple />
</div>
<div class="file_upload">
<input type="submit" value="Upload" class="upload_button" />
</div>
</form>
The files[] get uploaded OK but input "#id" is not in the $_POST array.
I need it because I want to pass the name of the directory that the images are to be stored in.
I notice that you are missing quotation marks around 'text' in
<input id='id' type=text name='id' value='H123'>
Which should be:
<input id='id' type='text' name='id' value='H123'>
Besides that I can't see any obvious reason why it shouldn't work.

jquery mobile .trigger('create') method doesn't work with iframe

When I try to call .trigger('create') method to iframe contents, it does not work and css classes are not applied to input:text elements. but when I call .trigger('create') method for html content outside the iframe, it works. Here is my javascript code.
var content = ' <form class="fbm_contactform">\
<div>Contact Us</div>\
<div data-role="fieldcontain"><label for="name" >Name</label>\
<input name="name" type="text" class="m-field" /></div>\
<div data-role="fieldcontain"><label for="email">Email</label>\
<input name="email" type="text" class="m-field" /></div>\
<div data-role="fieldcontain"><label >Message</label>\
<input name="message" type="text" class="m-field" /></div>\
<input name="submitButton" type="submit" class="m-field" value="Send Message" /></div>\
</form> ';
jQuery("#mobile_view").contents().find("#fbm_mob_menu").before(content);
jQuery("#mobile_view").contents().find(".fbm_contactform").trigger("create");
//console.log(jQuery("#mobile_view").contents().find(".fbm_contactform").html());
Console log prints the right html content.

Resources