Grails If Statement not working? - grails

I am currently trying to implement a nested if statement on a view in my Grails application. I have the code below which firstly checks to to if a value is true and if so it renders some code (this works). Then if this is not true it falls into the else statement, in here I need a nested If Statement to look at a value and render a different piece of code based on the value.
<g:if test="${a?.staticValue == true}">
<g:field type="text" name="staticText" readonly="true" value="${a?.data}"/>
</g:if>
<g:else>
<g:if test="${a?.type == 'Door'}">
<g:field type="text" name="doorField" value="" placeholder="${a?.wood}"/>
</g:if>
<g:elseif test="${a?.type == 'Floor'}">
<g:field type="text" name="floorField" value="" placeholder="${a?.laminate}"/>
</g:elseif>
<g:elseif test="${a?.type == 'Window'}">
<g:field type="text" name="windowField" value="" placeholder="${a?.blinds}"/>
</g:elseif>
</g:else>
Nothing gets rendered within the else statement and only the first box is shown so the nested if statements do not work for some reason and I don’t understand why. If I remove the if statement at the bottom and run the code below the value show "Door".
<g:field type="text" name="typeField" value="" placeholder="${a?.type}"/>
I don’t understand why this isn’t working and I am probably missing something silly but would really appreciate the help on this.
Thanks in advance
***EDIT****
So I have changed my code as suggested below to trim any white-space even though there shouldn’t be any and I get a weird error:
<g:if test="${a?.type.trim().equals('Door')}">
The error below seems to suggest that there is no data being pulled:
No signature of method: com.smstool.Dynam$VarType.trim() is applicable for argument types: () values: []
This is weird because I have added this else statement to the end and this return the value of "Door" to the view:
<g:else>
${a?.type}
</g:else>
Does anyone have any ideas what may be going on here as im confused :S Thanks

Try: if a?.staticValue is String try old java way:
<g:if test="${a?.staticValue}">
<g:field type="text" name="staticText" readonly="true" value="${a?.data}"/>
</g:if>
<g:else>
<g:if test="${a?.type.toString().equals('Door')}">
<g:field type="text" name="doorField" value="" placeholder="${a?.wood}"/>
</g:if>
<g:elseif test="${a?.type.equals('Floor')}">
<g:field type="text" name="floorField" value="" placeholder="${a?.laminate}"/>
</g:elseif>
<g:elseif test="${a?.type.equals('Window')}">
<g:field type="text" name="windowField" value="" placeholder="${a?.blinds}"/>
</g:elseif>
</g:else>
for case insensitive:
equals can be changed to : equalsIgnoreCase

Related

Missing string after space erb

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 %>">

Get value with $_POST from multiple brackets

<input type="text" class="text" id="attachments-1-vid_id" name="attachments[1][vid_id]" value="1qaq0F-SXpo8">
<input type="text" class="text" id="attachments-2-vid_id" name="attachments[2][vid_id]" value="2qaq0F-SXpo8">
<input type="text" class="text" id="attachments-3-vid_id" name="attachments[3][vid_id]" value="3qaq0F-SXpo8">
<input type="text" class="text" id="attachments-4-vid_id" name="attachments[4][vid_id]" value="4qaq0F-SXpo8">
This is my input. I want to check it with only [vid_id]. Is it possible?
If any input posted
if( isset($_POST['vid_id']) ) {
//do it...
}
You are accessing the vid_id index which isn’t really what is passed in the $_POST superglobal.
The solution is based on two assumptions.
Only that input exist.
This is pretty straight forward:
<?php
if(isset($_POST[‘attachments’][231][‘vid_id’]){}
OR
<?php
if(array_key_exists(“vid_id”, $_POST[‘attachments’][231])){}
Similar inputs also exist and you want to perform for multiple inputs.
By this, I mean..
<input type=text name=attachments[][vid_id] />
.....
<input type=text name=attachments[][vid_id] />
<input type=text name=attachments[][vid_id] />
For this, you have to insert it in a loop.
<?php
foreach($_POST[‘attachments’] as $arr){
if(array_key_exists(“vid_id”, $arr){
// do stuff
}
}

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">

Grails - Edit - does not retain the values when created

Grails issue :
When clicking over the Edit in the following screen : Domain and Variable values does not seem to retain their values (When creating it, we are able to enter the values - Domain and Variable, but it does not retain the values when editing..
Clicking over EDIT in the following screen :
does not retain the values of domain and variable alone:
.gsp code below
<tr>
<td>Domain<span style="color: red">*</span></td>
<td><g:if test="${isCreate}">
<g:select class="statSele" id="domain_name" name="domain_name" from="${com.datumrite.master.DomainMaster.list()}" optionKey="id" noSelection="['':'Select Domain']" onchange="${remoteFunction(
action:'driveVariableFromDomain',
params:'\'id=\'+escape(this.value)',
update: 'variable_select'
)}"></g:select> <br>
</g:if>
<g:else>
<input disabled="true" id="dN" name="name" type="text" style="margin-bottom:4px" value="${(data.domain_name instanceof String)?'':com.datumrite.master.DomainMaster.get(data.domain_name)}" />
</g:else>
</td>
</tr>
<tr>
<td>Variable<span style="color: red">*</span></td>
<td><g:if test="${isCreate}">
<span id="variable_select">
<g:select class="statSele" name="var_name" from="${[]}" value="${data?.var_name}" noSelection="['':'Select Variable']"></g:select></span> <br>
</g:if>
<g:else>
<input disabled="true" type="text" name="name" style="margin-bottom:4px;margin-left:5px" value="${data?.var_name}" />
</g:else></td>
</tr>
<tr>
<tr>
<td>Condition<span style="color: red">*</span></td>
<td><g:if test="${isCreate}">
<g:select class="statSele" id="constrain_type" name="constrain_type"
from="${['Lesser than','Greater than','Lesser than nor Equal','Greater than nor Equal','Equal To','Not Equal To']}"
value="${data?.constrain_type}" noSelection="['':'Select Condition']">
</g:select>
</g:if>
<g:else>
<input disabled="true" name="name" value="${data?.constrain_type}" type="text" style="margin-bottom:4px"/>
</g:else></td>
</tr>
And, I am using MySQL DB for the same.
can anyone help me with this issue ?
You need to make sure the subscription instance is passed when you click Edit link. (possibly under <g:link...> tag) The gsp you've posted is for create view. Check your List of Subscription view. (possibly show.gsp)

Change the width of a SINGLE JQuery Mobile Input field?

The other two answers on this question propose overriding
div.ui-input-text {}
However, I have multiple input fields on this page and also within my project. So those answers won't work as they would effect everything on my page or project.
How can I modify a single text input?
A class designation in the input tag doesn't work. If I encapsulate the input with a div tag it still doesn't work. I'm trying to put an icon at the end but it seems all Jquery mobile text input takes the entire screen.
<input class="address" type="text" name="address" id="basic"
placeholder="Street Address, City, State" />
<input type="button" value="FindMe" data-icon="eye" data-iconpos="notext">
CSS, No Effect!
.address {
width: 200px !important;
}
Now, I could still switch to Bootstrap if that's the better way to go on this project. It seems to have .col-xs-* classes that solve this problem.
Thanks in advance.
Instead of directly setting the class on the input,jQM provides a data-attribute for inputs called data-wrapper-class (api doc: http://api.jquerymobile.com/textinput/#option-wrapperClass). This allows you to apply a class directly to the outermost wrapping DIV that jQM adds when enhancing the textbox.
<input data-wrapper-class="address" type="text" name="address" id="basic"
placeholder="Street Address, City, State" />
Working DEMO
It is maybe bit late to answer this, but maybe for others looking for the same thing (I was :-)
You can put your address in a div:
<div class="myContainer">
<label id="lbAddress">Provide the address</label>
<input class="address" type="text" name="address" id="address" />
<input class="address" type="text" name="Street" id="Street" />
<input class="address" type="text" name="City" id="City" />
<input type="button" value="FindMe" data-icon="eye" data-iconpos="notext">
</div>
<div><input class="other" type="text" name="other" id="other"/></div>
Then select your container and just the input inside that container in the CSS:
.myContainer > .ui-input-text
{
width:200px;
}
demo: https://jsfiddle.net/petitbarzun/cfazq5k5/
Reading your comments on the answer from ezanker, if you want all the inputs to appear on one line, there needs to be a container with ui-field-contain like this (the label should be there too):
<div class="ui-field-contain">
<label id="lbAddress" style="display:none"></label>
<input class="address" type="text" name="address" id="address" />
<input class="address" type="text" name="Street" id="Street" />
<input class="address" type="text" name="City" id="City" />
<input type="button" value="FindMe" data-icon="eye" data-iconpos="notext">
</div>
<div><input class="other" type="text" name="other" id="other"/></div>
The CSS then looks like this:
.ui-field-contain > #lbAddress~[class*=ui-input-text]
{
width:219px;
}
demo http://jsfiddle.net/petitbarzun/cfazq5k5/1/

Resources