I have a textbox field with id="textbox1". How do I set its value?
This is what I tried:
query('#textbox1').text = 'test 123';
But it did not work.
InputElement input = querySelector("#textbox1");
input.value = "test123";
Tips : When you use querySelector(selector) you can type the result with what you expect (a InputElement here). Thus, editor will provide content assist to help you.
Note that query is now deprecated. For all those that find this through Google as I did, here is updated
InputElement input = querySelector("#textbox1");
input.value = "test123";
Related
First of all: Svelte is still new to me. I hope the question is not too trivial.
Within a simple component I want to use the content of a formatted input field for a calculation.
For example:
In the input field a Euro amount should be displayed formatted (1.000).
Next to it a text with the amount plus VAT should be displayed (1.190).
How I do this without formatting is clear to me. The example looks like this:
export let net;
export let vat;
$: gross = net + (net * vat / 100);
$: grossPretty = gross.toLocaleString('de-DE',{ minimumFractionDigits: 0, maximumFractionDigits: 0 });
with a simple markup like this:
<form>
<label>Net amount</label>
<input type="text" step="any" bind:value={net} placeholder="Net amount">
</form>
<div>
Gros = {grossPretty} €
</div>
In vue i used a computed property. Its getter delivers the formatted string and its setter takes the formatted string and saves the raw value.
(In data() I define net, in the computed properties i define netInput. The input field uses netInput as v-model).
It looks like this:
netInput: {
get(){
return this.net.toLocaleString('de-DE',{ minimumFractionDigits: 0, maximumFractionDigits: 0 });
},
set(s){
s = s.replace(/[\D\s._-]+/g, "");
this.net = Number(s);
}
}
How can I handle it in svelte?
You can do something somewhat similar, you create another computed variable that stores the deformatted string from the input field and is used in the calculation instead of the direct input
export let net;
export let vat;
$: net_plain = Number(net.replace(/[\D\s._-]+/g, ""));
$: gross = net_plain + (net_plain * vat / 100);
$: grossPretty = gross.toLocaleString('de-DE',{ minimumFractionDigits: 0, maximumFractionDigits: 0 });
But maybe find a better name for the variable :)
Thanks to Stephane Vanraes I found a solution.
It has not the charm of the vue approach but it's ok. First I inserted 'net_plain'. To have the input field formatted during input, I added an event listener for the keyup event.
<input type="text" step="any" bind:value={net} on:keyup={handleKeyUp} placeholder="Net amount">
The event is handled from the function handleKeyUp as follows:
function handleKeyUp(event){
if ( window.getSelection().toString() !== '' ) {
return;
}
// ignore arrow keys
let arrows = [38,40,37,39];
if ( arrows.includes( event.keyCode)) {
return;
}
let input = event.target.value.replace(/[\D\s._-]+/g, "");
input = input ? parseInt( input, 10 ) : 0;
event.target.value = ( input === 0 ) ? "" : input.toLocaleString( "de-DE" );
}
BUT: If anyone has a solution using getter and setter I would appreciate the anwer!
Can someone help me in creating the below xml structure using ESQL in IIB
Input:
<animal>
<animaldomestic>dog<animaldomestic>
<animalwild>cheetah<animalwild>
</animal>
Output:
<animals>
<animal type="domestic">cow</animal>
<animal type="wild">cheetah</animal>
</animals>
SET OuputRoot.XMLNSC.animals.(XMLNSC.Attribute)animal = 'domestic';
SET OutputRoot.XMLNSC.animals.animal = 'cow';
SET OuputRoot.XMLNSC.animals.(XMLNSC.Attribute)animal = 'wild';
SET OutputRoot.XMLNSC.animals.animal = 'cheetah';
I found solution for this.Please find the below code:
SET OutputRoot.XMLNSC.animals.animal[1].(XMLNSC.Attribute)type = 'domestic';
SET OutputRoot.XMLNSC.animals.animal[1]VALUE = InputRoot.XMLNSC.animal.animaldomestic;
SET OutputRoot.XMLNSC.animals.animal[2].(XMLNSC.Attribute)type = 'wild';
SET OutputRoot.XMLNSC.animals.animal[2]VALUE = InputRoot.XMLNSC.animal.animalwild;
If you want universal code:
DECLARE animal REFERENCE TO InputRoot.XMLNSC.animal.*[>];
DECLARE type CHAR;
DECLARE I INTEGER 1;
WHILE LASTMOVE(animal) DO
SET type = SUBSTRING(FIELDNAME(animal) AFTER 'animal');
SET OutputRoot.XMLNSC.animals.animal[I] = FIELDVALUE(animal);
SET OutputRoot.XMLNSC.animals.animal[I].(XMLNSC.Attribute)type = type;
SET I = I + 1;
SET type = '';
MOVE animal NEXTSIBLING;
END WHILE;
#Egorka_nazarov's solution is the best. A couple of improvements are possible, though:
FOR refAnimals AS InputRoot.XMLNSC.animal.*[];
CREATE LASTCHILD OF OutputRoot.XMLNSC.animals
AS refNewAnimal
TYPE NameValue
NAME 'animal'
VALUE FIELDVALUE(refAnimals);
DECLARE type CHARACTER SUBSTRING(FIELDNAME(refAnimals) AFTER 'animal');
SET refNewAnimal.(XMLNSC.Attribute)type = type;
END FOR;
The above code is shorter and less likely to contain bugs (once you have practiced with REFERENCE variables, obviously).
I get the following error in caret trainControl() using the custom methods syntax documented in the package vignette (pdf) on page 46. Does anyone know if this document out of date or incorrect? It seems at odds with the caret documentation page where the "custom" parameter is not used.
> fitControl <- trainControl(custom=list(parameters=lpgrnn$grid, model=lpgrnn$fit,
prediction=lpgrnn$predict, probability=NULL,
sort=lpgrnn$sort, method="cv"),
number=10)
Error in trainControl(custom = list(parameters = lpgrnn$grid, model = lpgrnn$fit, :
unused argument (custom = list(parameters = lpgrnn$grid, model = lpgrnn$fit,
prediction = lpgrnn$predict, probability = NULL, sort = lpgrnn$sort, method = "cv",
number = 10))
The cited pdf is out of date. The caret website is the canonical source of documentation.
I'm trying to make the input textbox of a raw_id_fields wider than the default size but without success.
Here is what I tried ('codarticolo' is the raw_id_fields) to no avail:
admin.py
class MovimentomagInline(admin.TabularInline):
codarticolo = forms.CharField(widget=forms.TextInput(attrs={'size': 80}))
raw_id_fields = ['codarticolo',]
fields = ('codarticolo', 'numconfezioni', 'numerounita','totalepezzi')
model = Movimentomag
extra=3
class MovimentomagOption(admin.ModelAdmin):
list_display = ('codarticolo', 'numconfezioni', 'numerounita','totalepezzi')
fields = ('codarticolo', ('numconfezioni', 'numerounita','totalepezzi',))
class MovimentoOperazioneOption(admin.ModelAdmin):
list_display = ('segno', 'data_movimento', 'paziente','operatore')
fields = (('segno','data_movimento'),('paziente','operatore'))
inlines = [MovimentomagInline,]
order_by = ['-data_movimento',]
What should I do?
Ciao
Vittorio
Probably 5 years too late :(.
I was facing the same issue. The following should work.
attrs={'style': 'width: 80px'}
What it does is to set the style property of the HTML input element.
Hope it helps.
I am generating a report using OpenXML and exporting it to excel. I want to protect the excel sheet except for a particular cell.
If anyone has worked on this before, kindly help
Thanks,
Amolik
PageMargins pageM = worksheetPart.Worksheet.GetFirstChild<PageMargins>();
SheetProtection sheetProtection = new SheetProtection();
sheetProtection.Password = "CC";
sheetProtection.Sheet = true;
sheetProtection.Objects = true;
sheetProtection.Scenarios = true;
ProtectedRanges pRanges = new ProtectedRanges();
ProtectedRange pRange = new ProtectedRange();
ListValue<StringValue> lValue = new ListValue<StringValue>();
lValue.InnerText = "A1:E1"; //set cell which you want to make it editable
pRange.SequenceOfReferences = lValue;
pRange.Name = "not allow editing";
pRanges.Append(pRange);
worksheetPart.Worksheet.InsertBefore(sheetProtection, pageM);
worksheetPart.Worksheet.InsertBefore(pRanges, pageM);
ref : http://social.msdn.microsoft.com/Forums/en-US/a6f7502d-3867-4d5b-83a9-b4e0e211068f/how-to-lock-specific-columns-in-xml-workbook-while-exporting-dataset-to-excel?forum=oxmlsdk
Have you tried using the OpenXML Productivity Toolkit?
from what I can see you have to add a
new CellFormat
with attribute
ApplyProtection = true
to
CellFormats
append
new Protection
with attribute
Locked = false
to the the CellFormat you created.
CellFormat is a element of CellFormats which is a element of Stylesheet
then to the Worksheet you add a
new SheetProtection(){ Password = "CC1A", Sheet = true, Objects = true, Scenarios = true };
I havent tried this, but it should be easy enought to find out what you need to do with the Productivity Toolkit. I hope this points you and anyone trying to do this in the right direction.