I want to create my selection to sort only 'A' in listbox
This is my code
class account_voucher(osv.Model):
_inherit = 'account.voucher'
_columns = {
'amount': fieSome one plz help me and thank you for you time to rend my word (sorry about my language :'|)lds.float('Fees', digit=(12,2)),
'amount_mode': fields.selection([('a', 'A'),('b', 'B')], 'Amount Mode', select=True, change_default=True, track_visibility='always'),
}
and This is my xml view
<field name="amount_mode" style="width:11em" domain="[('amount_mode'), '=', 'a']"/>
Am i use the wrong systax or what?
Some one plz help me and thank you for you time to rend my word (sorry about my language :'|)
Your syntax is wrong.
Structure of Domain is =>
domain=[('field_value','operator','value')]
correct is:-
<field name="amount_mode"
style="width:11em"
domain="[('amount_mode', '=', 'a')]"
You can also add domain in .py file field also.
And if you want to see that value is selection box default than you can add in .py file
for example.
_defaults = {
'amount_mode': 'a',
}
Related
AttributeError: 'SelectionItem' object has no attribute 'text'
Hey , How can I get text from SelectionItem , where ; a OneLineAvatarListItem is SelectionItem?! Please help me.
Here is a solution using Python3.X and Regular Expressions which extracts only alphanumeric words including spaces and full stops(which would be necessary for forming a syntactically correct phrase(s))
import re
new_text = ''.join(re.findall('[A-Za-z0-9. ]', SelectionItem))
print(new_text)
My problem is when I use the character ', Thymeleaf converts it to '.
I need to show the apostophes instead.
My string is saved in SQL like this:
"body" : "L'' autorizzazione di EUR [[${ #numbers.formatDecimal(#strings.replace(amount,'','',''.''),1,''POINT'',2, ''COMMA'')}]] in [[${date}]] ore [[${time}]] c/o presso [[${merchant}]] รจ stata negata. [[${ #strings.replace(refuseMessage,'',/'/g)}]]"
I tried string.replace but it doesn't work. Can somebody help me please?
Are you creating HTML? Then ' is correct, and you don't need to replace it.
If you are not creating HTML, then you need to make sure your template resolver is set to an appropriate template mode, for example, TEXT:
templateResolver.setTemplateMode(TemplateMode.TEXT);
I've stored a string in the database. When I save and retrieve the string and the result I'm getting is as following:
This is my new object
Testing multiple lines
-- Test 1
-- Test 2
-- Test 3
That is what I get from a println command when I call the save and index methods.
But when I show it on screen. It's being shown like:
This is my object Testing multiple lines -- Test 1 -- Test 2 -- Test 3
Already tried to show it like the following:
${adviceInstance.advice?.encodeAsHTML()}
But still the same thing.
Do I need to replace \n to or something like that? Is there any easier way to show it properly?
Common problems have a variety of solutions
1> could be you that you replace \n with <br>
so either in your controller/service or if you like in gsp:
${adviceInstance.advice?.replace('\n','<br>')}
2> display the content in a read-only textarea
<g:textArea name="something" readonly="true">
${adviceInstance.advice}
</g:textArea>
3> Use the <pre> tag
<pre>
${adviceInstance.advice}
</pre>
4> Use css white-space http://www.w3schools.com/cssref/pr_text_white-space.asp:
<div class="space">
</div>
//css code:
.space {
white-space:pre
}
Also make a note if you have a strict configuration for the storage of such fields that when you submit it via a form, there are additional elements I didn't delve into what it actually was, it may have actually be the return carriages or \r, anyhow explained in comments below. About the good rule to set a setter that trims the element each time it is received. i.e.:
Class Advice {
String advice
static constraints = {
advice(nullable:false, minSize:1, maxSize:255)
}
/*
* In this scenario with a a maxSize value, ensure you
* set your own setter to trim any hidden \r
* that may be posted back as part of the form request
* by end user. Trust me I got to know the hard way.
*/
void setAdvice(String adv) {
advice=adv.trim()
}
}
${raw(adviceInstance.advice?.encodeAsHTML().replace("\n", "<br>"))}
This is how i solve the problem.
Firstly make sure the string contains \n to denote line break.
For example :
String test = "This is first line. \n This is second line";
Then in gsp page use:
${raw(test?.replace("\n", "<br>"))}
The output will be as:
This is first line.
This is second line.
lets say we have some grammar like this.
Model:
greeting+=Greeting*;
Greeting:
'Hello' name=ID '!';
I would like to check whether the text written text in name is a valid text.
All the valid words are saved in an array.
Also the array should be filled with words from a given file.
So is it possible to check this at runtime and maybe also use this words as suggestions.
Thanks
For this purpose you can use a validator.
A simple video tutorial about it can be found here
In your case the function in the validator could look like this:
public static val INVALID_NAME = "greeting_InvalidName"
#Check
def nameIsValid(Greeting grt) {
val name = grt.getName() //or just grt.Name
val validNames = NewArrayList
//add all valid names to this list
if (!validNames.contains(name)) {
val errorMsg = "Name is not valid"
error(errorMsg, GreetingsPackage.eINSTANCE.Greeting_name, INVALID_NAME)
}
}
You might have to replace the "GreetingsPackage" if your DSL isn't named Greetings.
The static String passed to the error-method serves for identification of the error. This gets important when you want to implement Quickfixes which is the second thing you have asked for as they provide the possibility to give the programmer a few ideas how to actually fix this particular problem.
Because I don't have any experience with implementing quickfixes myself I can just give you this as a reference.
.txt file looks like
Euro
US Dollar
Australian Dollar
Pounds Sterling
Swiss Franc
and so on.
I have tried things like XDocument and ObservableCollection but can't seem to get them to work.
I would rather not hard code so much into xaml.
thanks,
Assuming you're sending the file with the project (file Build action set to "Content"), here's what you need:
First, add a ListBox to the Page called CurrenciesListBox, then add this code on the page load event or constructor:
var xapResolver = new System.Xml.XmlXapResolver();
using (var currenciesStream = (Stream)xapResolver.GetEntity(new Uri("Currencies.txt", UriKind.RelativeOrAbsolute), "", typeof(Stream)))
{
using (var streamReader = new StreamReader(currenciesStream))
{
while (!streamReader.EndOfStream)
{
CurrenciesListBox.Items.Add(streamReader.ReadLine());
}
}
}
Remember to change the filename above to match your file!
This is for starter, there are better ways to do the job (using MVVM)!