How can I escape a round bracket (right parenthesis) without closing it in a fragment?
"fragments/questionaire :: questionaire('00001_c-1',
${
{
'...',
'...',
'First 1) ...'
}
},
${
{
'...',
'...',
'...'
}
},'[0,2]')"
Kind of same effect is if keyword new is somewhere in the string.
already tried: 'First 1\) ...' ) ) inside utext
I use it to iterate over an object with questions and hints like:
th:fragment="questionaire(key, questions, hints, rightIndex)"
It's inside a form
<div th:each="aquestion, iterStat : ${questions}" th:with="qid=${key}+'_q-'+${iterStat.index},name='rb-'+${key}">
<div>
<input type="checkbox" th:name="${name}+${'_q-'+iterStat.index}" th:value="0" th:data-s="${iterStat.index}" th:id="${qid}" autocomplete="off" th:checked="${bucket.read('questionaire.'+name+'_q-'+iterStat.index)}==('' + 1)"/>
<label th:for="${qid}" th:text="${aquestion}"></label>
<input type="hidden" th:name="${name}+${'_q-'+iterStat.index}" value="0">
</div>
<div class="hint" th:id="${qid+'--hint'}" th:text="${hints[iterStat.index]}"></div>
</div>
<p class="submitContainer">
<button th:data-qvalidate="|quest${key}|" th:text="#{q.check}">Check</button>
</p>
Following on from my most recent comment in the question...
The least-worst solution I have is to create a Java string variable and add that to your model:
model.put("cp", ")");
where cp means "close parenthesis".
Then you can create a fragment parameter like this:
|foo 1${cp} bar|
And that passes the string foo 1) bar to the fragment without that "selector syntax" error you are currently getting.
<div th:replace="fragments/frag.html :: frag(|foo 1${cp} bar|)"></div>
And my fragment is just this:
<div th:fragment="frag(key)">
<div th:text="${key}"></div>
</div>
I would be happy to learn of a better solution.
Related
Sounds simple, but I couldn't find a hello-world example of this, despite the richness of the doc. The closest I could find was in https://react-hook-form.com/advanced-usage, in the Working with virtualized lists section, but that relies on another module react-window, which introduces further complexity.
I want to allow the admin user to create-update-delete a list of products, with various properties.
My current code in JSX looks like this, I'd like to take advantage of error handling etc from react-hook-form:
<ol >
{products.map((row, index) => (
<li
className={index === selectedProductIndex ? "selected" : ""}
key={index}
id={index} onClick={handleSelectProduct}>
{row.name}
</li>
))}
</ol>
<form onSubmit={handleSaveProduct}>
<p>Product name: </p>
<input name="productName" type="text" value={selectedProductName}
onChange={handleEdit_name} />
(... more properties to edit here)
</form>
The handlers save the values of selectedProductName, selectedProductIndex, etc in useState, in a database via axios, etc.
I'm handling the values of each field individually in the useState, which I'm aware is laborious and heavy-handed.
Well the answer was quite simple, although it took me a while to figure it out.
In most of the examples, the onChange or onClick handlers don't use the event object, but nothing prevents you from adding it in. Then there's the setValue function to set the other control's value. Here's the code of a hello-world example. It offers one dropdown and one input field, the input field updates to match the selected value of the dropdown.
import React from "react";
import {useForm} from "react-hook-form";
function Test() {
const {register, handleSubmit, errors, setValue} = useForm();
const mySubmit = data => {
console.log(data);
}
return (
<div>
<form onSubmit={handleSubmit(mySubmit)} className="reacthookform">
<select name="dropdown" ref={register}
onChange={(ev) => setValue("productName", ev.target.value)}>
{["AAA", "BBB", "CCC"].map(value => (
<option key={value} value={value}>
{value}
</option>
))}
</select>
<input name="productName" defaultValue="AAA" ref={register({required: true})} className="big"/>
{errors.productName && <p className="errorMessage">This field is required</p>}
<input type="submit" value="Save product"/>
</form>
</div>
);
}
export default Test;
Sorry for my English.
I need to change input value format, for example: from "1000000" to "1 000 000 $".
In my views of rails app, I have this line of code:
<%= ng_text_field('total_price', 'selected.data.total_price', 'Full price', ng_readonly: '!selected.permissions.update') %>
In helper:
def ng_text_field(name, ng_model, placeholder, options = {})
result = <<-HTML
<div class="form-group" ng-class='{"has-error":errors.#{name}}' #{options[:ng_if] && "ng-if=\"#{options[:ng_if]}\""}>
<label for="#{name}" class="col-sm-3 control-label">#{placeholder}</label>
<div class="col-sm-9">
<input id="#{name}"
type="text"
class="form-control"
name="#{name}"
placeholder="#{placeholder}"
ng-model="#{ng_model}"
#{options[:ng_readonly] && "ng-readonly=\"#{options[:ng_readonly]}\""}>
<p class="help-block small" ng-if="errors.#{name}">{{errors.#{name} | join:',' }}</p>
</div>
</div>
HTML
result.html_safe
end
I am know Angular very little, I have tried some ways and all this ways was incorrect. :(
Could anyone give advice of some help?
Thank you in advance
You're going to need to create a new directive that requires ngModel and applies the appropriate $parser/$formatter to it.
https://docs.angularjs.org/api/ng/type/ngModel.NgModelController#$parsers
A good example of how to do this is (displaying as uppercase but always storing data as lowercase):
ngModel Formatters and Parsers
You should be able to then add the ability to include other directives in your 'options' argument so that they get added correctly to the output.
I had a little problem on Prestashop 1.7.2.0, I want to add some field in my contact us form but don't know how to proceed.
I just find tuto for PS 1.6.
If someone could help me.
Thanks a lot
Here a no update resistant solution to add a field Name:
I tried the following thing to add a field (and remember this solution is not update proof and the additional fields are not safed in the backoffice):
Update contact.html + contact.txt in the theme/mails folder:
<span style="color:#333"><strong>Name: {contactname}</strong></span><br /><br />
Add the contactname line to the $var_list array in the file contactform.php located in the modules/contactform folder:
$var_list = [
'{order_name}' => '-',
'{attached_file}' => '-',
'{message}' => Tools::nl2br(stripslashes($message)),
'{email}' => $from,
'{product_name}' => '',
'{contactname}' => Tools::nl2br(stripslashes($contactname)),
];
Add a line to the beginning of the function sendMessage(){ in the same file (contactform.php)
$contactname = trim(Tools::getValue('contactname'));
Add the following lines to the part in the file contactform.tpl located in the theme/modules/contactform/views/template/widget folder:
<div class="form-group row">
<label class="col-md-3 form-control-label">{l s='Name' d='Shop.Forms.Labels'}</label>
<div class="col-md-6">
<input
class="form-control"
name="contactname"
type="text"
value="{$contact.contactname}"
placeholder="{l s='Ihr Name' d='Shop.Forms.Help'}"
>
</div>
</div>
I know it's ugly, but hey, it's a start :) as soon as prestashop 1.7 is not buggy anymore I will start programming with proper overrides/modules
This line of code is meant to use POSTBACK:
<form action = "<?php echo $_SERVER["PHP_SELF"];?>" method="post" />
i keep getting these errors:
Line 73, Column 46: an attribute value literal can occur in an attribute specification list only after a VI delimiter
Line 73, Column 47: character data is not allowed here
What exactly is wrong with the code to bring up these errors???
And i have to use this particular method to get full marks.
Also with this code:
<input type="password" name="password" id="password" size="" maxlength="20" />
it keeps bringing up this error:
Line 78, Column 78: document type does not allow element "input" here; missing one of "p", "h1", "h2", "h3", "h4", "h5", "h6", "div", "pre", "address", "fieldset", "ins", "del" start-tag
Help?
From the code you have provided I would say that your input tags are not inside a "container" tag. (your p's, div's, span's etc)
wrap your inputs in one of those and it should remove that validation message:
<form action="<?php echo $_SERVER["PHP_SELF"];?>" method="post">
<p> <!-- CONTAINER TAG FOR VALIDATION -->
Checkbox: <input type="checkbox" name="checktest" value="on"
title="checkbox sample"><br>
RadioButton1: <input type="radio" name="rbtest" value="one"
title="radio button1 sample"><br>
RadioButton2: <input type="radio" name="rbtest" value="two" checked="checked"
title="radio button2 sample"><br>
Text: <input type="text" name="texttest" title="text input sample"><br>
Password: <input type="password" name="passtest" title="pwd sample"><br>
<input type="submit" value="Send"> <input type="reset">
</p>
</form>
Regarding your other messages, this is what the W3C documentation states about the errors you are receiving:
Line 73, Column 46:
111: an attribute value literal can occur in an attribute specification list only after a VI delimiter
Have you forgotten the "equal" sign marking the separation between the attribute and its declared value? Typical syntax is attribute="value".
As mentioned you should not have the space between action and =
Line 73, Column 47:
63: character data is not allowed here You have used character data
somewhere it is not permitted to appear. Mistakes that can cause this
error include:
putting text directly in the body of the document without wrapping it
in a container element, or forgetting to
quote an attribute value (where characters such as "%" and "/" are
common, but cannot appear without surrounding quotes), or using
XHTML-style self-closing tags (such as ) in HTML 4.01 or
earlier. To fix, remove the extra slash ('/') character.
This one is probably because you are self-closing the form tag
change it to:
<form action="<?php echo $_SERVER["PHP_SELF"];?>" method="post">
(replace the /> with >)
Here is my HTML:
<div ng-app="angularApp">
<div ng-controller="testCtrl">
testKey = {{testKey}}<br />
Test 1: <input type="text" ng-model="test.myKey" />{{test[testKey]}}<br />
Test 2: <input type="text" ng-model="test[testKey]" />{{test[testKey]}}
</div>
</div>
Here is the js:
angular.module('angularApp', []);
function testCtrl($scope)
{
$scope.testKey = "myKey";
}
I setup and example here
Why does Test 1 work but Test 2 not work? Are "[" not allowed in the ng-model directive?
Here a working example. The problem is very simple, test.[testKey] isn't valid, you want test[testKey]. And you need to define test as an object on the controller because you cannot set a property of an undefined variable.