<c:if test="#{active eq status }">
<label class="switch">
<h:selectBooleanCheckbox class="input" id="sta" value="#{CMB.check}" />
<span class="slider round"></span>
</label>
</c:if>
i am trying to compare two variable but it is always returning false although varibles values are equals
Related
<div class="form-group required">
<label class="col-sm-2 control-label" for="input-telephone1">Confirm Telephone</label>
<div class="col-sm-10">
<input type="tel" name="telephone1" value="" placeholder="Confirm Telephone" id="input-telephone1" class="form-control" required/>
<?php if ($error_telephone1) { ?>
<div class="text-danger"><?php echo $error_telephone1; ?></div>
<?php } ?>
</div>
</div>
I am getting an error message even though I have already defined a variable in language and controller. Error message is given below:
errorNotice: Undefined variable: error_telephone1 in /home/chaarms/public_html/catalog/view/theme/default/template/account/register.tpl on line 85
in corresponding controller file, in your case catalog/controller/account/register.php you should define it:
$data['error_telephone1'] = "some code where from you want to get this info";
for example if you want to add some text code should be next:
$data['error_telephone1'] = $this->language->get('error_telephone1');
and in corresponding language file add:
$_['error_telephone1'] = 'Telephone error!!!';
that's all.
I am new in Thymeleaf, had searched on the web and SO for usage of html regex. I am not passing a th:object to my frontend for this page, hence What I would like is to handle validation with a pattern attribute in the form input. Would like to warn user if they don't enter extension for the file. (".xml" in this case). So I'd like to see if string contains substring or not.
However could not see why following fails.
(Used the fileName field with pattern="/xml/", since static value is being checked on the regex. Also tried th:pattern but no luck.)
<html xmlns:th="http://www.thymeleaf.org" xmlns:layout="http://www.ultraq.net.nz/web/thymeleaf/layout" layout:decorator="#{layouts/main}">
<div layout:fragment="content" class="container">
<div class="page-header">
<h2>Add New Project</h2>
</div>
<!-- multistep form -->
<div id="msform">
<!-- progressbar -->
<ul id="progressbar">
<li class="active">Project Details</li>
<li>Choose operations</li>
<li>Save operations</li>
<li>project saved</li>
</ul>
<form id="project-details" class="project" method="post">
<h2 class="fs-title">Project Details</h2>
<h3 class="fs-subtitle">This is step 1</h3>
<input type="text" th:field="${testSuitProject.name}" placeholder="Project Name" />
<input type="text" th:field="${testSuitProject.endpoint}" placeholder="Service End Point" />
<input type="text" th:field="${testSuitProject.fileName}" placeholder="FileName ex: sample_project.xml" pattern="/xml/" />
<input type="submit" name="next" id="btn-first" class="next action-button" value="Next" />
</form>
</div>
</div>
Any suggestions appreciated.
Your regex is simply wrong. To match string to end with ".xml":
<input type="text" placeholder="FileName ex: sample_project.xml" pattern=".*\.xml" />
.* = match any characters (in the beginning of the string).
\. = a literal dot, since dot means any character in regex.
(Maybe you confuse with JavaScript where reg expression is surrounded by /:es to create a regex object.)
I'm trying to render the template in GSP page
template:
<div class="container">
${body()}
</div>
template call:
<g:render template="/shared/wrapperTemplate">
<g:textField name="${property}" value="${value}" id="${property}id" class="form-control"/>
</g:render>
The body() is evaluated correctly and renders
<input type="text" name="name" value="" id="nameid" class="form-control" />
but when passing it to the template, it is surrounded by the quotes and instead of displaying input field, it prints the html input as string to the html page
I also tried with write TagLib
def fieldTemplate = { attrs, body ->
out << render(template: "/shared/wrapperTemplate", model: [content: body()])
}
But the result was the same (of course I had to change the tag call)
The idea was to reuse the formatting part of the template <div> for all _wrapper.gsp templates in Fields plugin, but not copy paste it. The case above is simplified, but I use Twitter Bootstrap and there is a bunch of lines that I don't want to copy.
_fields/default/_wrapper.gsp:
<div class="form-group ${hasErrors(bean:bean,field:property,'has-error')}">
<label for="${property}id" class="col-sm-2 control-label">${label}</label>
<div class="col-sm-10">
<g:textField name="${property}" value="${value}" id="${property}id" class="form-control" />
</div>
</div>
_fields/date/_wrapper.gsp:
<div class="form-group ${hasErrors(bean:bean,field:property,'has-error')}">
<label for="${property}id" class="col-sm-2 control-label">${label}</label>
<div class="col-sm-10">
<g:datePicker name="${property}" value="${value}" precision="day" id="${property}id" class="form-control" />
</div>
</div>
I am not able to understand the following lines of your post
but when passing it to the template, it is surrounded by the quotes
and instead of displaying input field, it prints the html input as
string to the html page
What is it in this case, please share the exact code which is not working.
The first example you shared is working for you, in the second example you passed content as parameter. When you are passing the parament then you need to change your code from
${body()}
to
${raw(content)}
I am still not sure what is the exact code which not working, just a wild guess.
In the code above how can I search for editEntidadeXXX on the name attribute and then insert this value on the id attribute?
Something like editEntidade(\w)+ will found the names but it is possible to insert that values on the edit attribute?
<div class="control-group column-group horizontal-gutters">
<label class="large-15 small-100 content-right" for="editEntidadeRua">Rua</label>
<div class="control large-40 medium-40 small-100">
<input type="text" id="editEntidade" name="editEntidadeRua" value="<?php echo html_escape($entidadeValues['rua']) ?>">
</div>
</div>
<div class="control-group column-group horizontal-gutters">
<label class="large-15 small-100 content-right" for="editEntidadeCodpostal">Código Postal</label>
<div class="control large-10 medium-10 small-100">
<input type="text" id="editEntidade" name="editEntidadeCodpostal" value="<?php echo html_escape($entidadeValues['codpostal']) ?>">
</div>
</div>
Find What:
id="editEntidade"(\s+)name="editEntidade(\w+)"
Replace With:
id="editEntidade$2" name="editEntidade$2"
I am unable to figure out how to loop over the questionTypes and get selected questionType value. Based on the selected questionType I have to add answers for multioption questions, like in choose the correct answers we provide four choices out of which one we have to select as correct answer.
I have tried to use cfswitch but it does not seem to work:
<html>
<head> <script src="http://code.jquery.com/jquery-latest.js"></script></head>
<body>
<cfoutput>
<cfif not IsDefined('rc.questionType')>
<form class="form form-horizontal" action="#buildUrl('question.new')#" method="post">
<input type="hidden" name="surveyId" value="#rc.surveyId#">
<fieldset>
<div class="control-group">
<label class="control-label" for="questiontype">Question type</label>
<div class="controls">
<select name="questionType" onchange="this.form.submit()">
<option value="0" >Select question type</option>
<cfloop query="rc.types">
<option value="#id#">#name#</option>
</cfloop>
</select>
</div>
</div>
</fieldset>
</form>
<!--- if question type is defined, display question form --->
<cfelse>
<form class="form form-horizontal" action="#buildUrl('question.save')#" method="post">
<input type="hidden" name="id" value="0">
<input type="hidden" name="surveyId" value="#rc.data.fksurveyId#">
<input type="hidden" name="questionTypeId" value="#rc.data.fkquestionTypeId#">
<input type="hidden" name="rank" value="#rc.data.rank#">
<fieldset>
<div class="control-group">
<label class="control-label" for="question">Question</label>
<div class="controls">
<input class="input-xxlarge" type="text" name="question" id="question" required="true" placeholder="write your question">
</div>
</div>
<div class="control-group">
<label class="control-label" for="Required">Required</label>
<div class="controls">
<select name="Required">
<option value="1" selected>Yes</option>
<option value="0">No</option>
</select>
</div>
</div>
<!--- question arguments for selected type, this will be for multioption questions --->
<!--- <cfif rc.questiontype is "multiple choice (single selection),Multiple Choice (Multi Selection) with Other,Multiple Choice (Single Selection) with Other,Multiple Choice (Multi Selection)"> --->
<cfswitch expression="#rc.questiontypeid#">
<cfcase value="multiple choice (single selection),Multiple Choice (Multi Selection) with Other,Multiple Choice (Single Selection) with Other,Multiple Choice (Multi Selection)">
<div class="control-group">
<label class="control-label" for="answer">Answer</label>
<div class="controls">
<input class="input-xxlarge" type="text" name="new_answer" id="new_answer">
</div>
</div>
<div class="control-group">
<label class="control-label" for="rank">rank</label>
<div class="controls">
<input class="input-mini" type="text" name="rank" id="rank">
</div>
</div>
<div class="control-group">
<label class="control-label" for="answer">Answer</label>
<div class="controls">
<input class="input-xxlarge" type="text" name="new_answer" id="new_answer">
</div>
</div>
<div class="control-group">
<label class="control-label" for="rank">rank</label>
<div class="controls">
<input class="input-mini" type="text" name="rank" id="rank">
</div>
</div>
</cfcase>
</cfswitch>
<!--- --->
<div class="form-actions">
<button type="submit" class="btn btn-primary">Save</button>
Cancel
</div>
</fieldset>
</form>
</cfif>
<cfdump var="#rc#">
</cfoutput>
</body>
</html>
This is my controller method to add a new question:
<cffunction name="new" returntype="void" access="public">
<cfargument name="rc" type="struct" required="true">
<!---call service to get the textfields, checkboxes etc,. based on questiontype selection --->
<!--- call service to get question types for select box --->
<cfset rc.types = getQuestionService().types()>
<cfset rc.action = 'New Question'>
<!--- if user select question type --->
<cfif isdefined('arguments.rc.questionType')>
<cfset rc.data = getQuestionService().new(arguments.rc.surveyId, arguments.rc.questionType)>
</cfif>
</cffunction>
I have two forms in single page. In the first form I am selecting questionType. Based on the selected questionType I have to display an add question form.
To make sure I'm reading how this code is supposed to work:
1. This is a form to create the question, not answer it.
2. rc is a struct with your basic question definition as the keys and you have other existing code that insures that the rc structure will exist on this page.
(Rather than isDefined("rc.questionType") I'd use structKeyExists(rc, "questionType"), but that's a whole different discussion.
3. When you change the value of the Question Type, that field is submitted back and other code creates and populates the questionType key of rc struct. So isDefined('rc.questionType') should now be TRUE (moving you to the cfelse block).
4. You are now brought back to the same page with a field to enter the question, whether it's required, and you're looking for the Answer entry boxes based on the questionType.
If all of those assumptions are correct, then this is the point that you would need to loop through your options for your answers. The cfswitch/cfcase is correct, but some of those multiple choice options will need to be handled slightly differently. The ones with "Other" options will need slightly more processing on this end and on the answer tracking end. You'll have to add a text box for that checked answer.
So you'll need a little more definition for the questions in the rc struct. You need to track which one is the correct answer (a simple checkbox). If you want to allow a dynamic number of multi-choice answers, you'll need to keep track of how many answers you'll need. And you could even keep these multi-choice answer options together if you tracked whether the answer was an "Other" or not. This would also allow you to have multiple "Other"-type selections in the multi-choice options. Granted, that would reduce your choices for whether this is a multi-choice question down to just one, simply "Multiple Choice". Let the answers determine whether it's single selection or "Other" selection. And if you wanted to use radio buttons instead of check boxes for the single selects, all you'd have to do is count the answers for the question. Then you can worry about each basic questionType seperately.
The code to better track the answers (correct and "Other" options) will also need to be pulled back up, likely in the getQuestionService() function, which is where I'm assuming you're pulling your question definition and populating the rc struct.
Do you plan on using this form as an UPSERT, or is this simply an INSERT and you'll UPDATE/EDIT the questions elsewhere?
Regardless, back to your original question. The first thing I'd recommend would be to also cfdump the rc struct at the top of the page. See what data you're initially working with.
Down where you need to add your Answers, the cfswitch is the correct method. You likely aren't matching any of your cases here. Output rc.questionTypeID here to see what your value is. And I'd use an integer ID for the question type rather than the name of the question type. It'll give faster, more precise processing. When you get the correct case, you'll need to cfloop your answers here.
To select which one is the correct one, simply add a selected="selected" or checked="checked" (depending on input type) inside of a cfif that checks if the current answer is the correct answer.
Since the switch expression is set to rc.questiontypeid, the case value should be the possible rc.questiontypeid, not the question type name.