AutoNumeric Multiple Class using preset Languages - autonumeric.js

The goal here is to set all the .class values (.multiple) with the preset languages and being able to modify things like decimal places or remove the currency symbol.
This works only for one class.
new AutoNumeric('.num-format').french().update({decimalPlaces: 0});
or this.
new AutoNumeric.multiple('.num-format', 'French');
new AutoNumeric.multiple('.num-format', 'French').update({decimalPlaces: 0});
This WILL work with all the classes BUT I cant figure out how to do things like set the decimal places?
new AutoNumeric.multiple( '.num-format', AutoNumeric.getPredefinedOptions().French );
I have pretty much tried all the options imaginable.
Thanks.

You can proceed with 2 different ways:
Either pass all your different options object during the initialization; those will be merged together.
If an option is defined in multiple option objects, then the latter object option will overwrite the previous one.
Or use forEach() on the given AutoNumeric element array to update the options in one call
// AutoNumeric initialisation for multiple elements
// Here you can see that multiple options objects can be added, and will be merged in the given order
const anElementsStatic = new AutoNumeric.multiple('.static > .num-format', 42, ['French', { decimalPlaces: 0 }]);
// AutoNumeric initialisation for multiple elements
const anElements = new AutoNumeric.multiple('.mod > .num-format', [61, 62, 63, 64], ['French', { decimalPlaces: 0 }]);
// ...then we can update the options globally for all 4 fields with one function call:
anElements[2].update({ decimalPlaces: 3 }); // Modify only a specific element in the array
anElements.forEach(a => a.update({ currencySymbol: '#' })); // Modify all elements at once
You can check how it works on this codepen.

Related

Changing the name of a list on the fly using a counter

I have a set of list,
list_0=[a,b,a,b,b,c,f,h................]
list_1=[f,g,c,g,f,a,b,b,b,.............]
list_2=[...............................]
............
list_j=[...............................]
where j is (k-1), with some thousands of value stored in them. I want to count for how many times a specific value is in a specific list. And I can have only 8 different values (I mean, every single element of those list can only have one out of 8 specific values, let's say a,b,c,d,e,f,g,h; so I want to count for every list how many times there's the value a, how many times the value b, and so on).
This is not so complicated.
What is complicated, at least for me, is to change on the fly the name of the list.
I tried:
for i in range(k):
my_list='list_'+str(int(k))
a_sum=exec(my_list.count(a))
b_sum=exec(my_list.count(b))
...
and it doesn't work.
I've read some other answer to similar problem, but I' not able to translate it to fit my need :-(
Tkx.
What you want is to dynamically access a local variable by its name. That's doable, all you need is locals().
If you have variables with names "var0", "var1" and "var2", but you want to access their content without hardcoding it. You can do it as follows:
var0 = [1,2,3]
var1 = [4,5,6]
var2 = [7,8,9]
for i in range(3):
variable = locals()['var'+str(i)]
print(variable)
Output:
[1, 2, 3]
[4, 5, 6]
[7, 8, 9]
Although doable, it's not advised to do this, you could store those lists in a dict containing their names as string keys, so that later you could access them by simply using a string without needing to take care about variable scopes.
If your names differ just by a number then perhaps you could also use a list, and the number would be the index inside it.

how to creat multiple empty dictionaries from names in a list in python?

I need to create multiple dictionaries from a list. if list is ['dic1','dict2'], i want to creat two different dictionaries such as sample_dic1 and sample_dic2.
if I don't use loops, I'll just type:
sample_dic1=dict();sample_dic2=dict()
my question is how to do it in a loop from a name list.
I tried to put the list in loop while each value of the loop equal to dict().
However, it does not assign the left-hand side to dict().
di_list=['dic1','dict2']
for (a) in di_list:
'sample_{}'.format(a)=dict()
I also Tried this. it doesn't give any error. but doesn't work neigher
temp=dict()
di_list=['dic1','dict2']
for (a) in di_list:
temp[a]='sample_{}'.format(a)
temp[a]=dict()
so I want to creat these two dictrionaries from di_list values. with 'sample_{}'.format(a) I can creat my desired name, But binding it to dict() doesn't work. i.e,. sample_{}'.format(a)=dict()
I think you're mixing two things: variables names and values. Variable names do not have a real effective meaning and if you consistently change their names the program remains the same (in fact, it happens in most languages under the hood anyway).
Here is an option to refer to an arbitrary number of values by name, using a dictionary (name->value):
temp=dict()
di_list=['dic1','dict2']
for (a) in di_list:
temp['sample_{}'.format(a)] = dict()
Now you can verify the values are in fact there:
assert temp['sample_dic1'] == {} # True
assert temp['sample_dict2'] == {} # True

Add empty option to List Validator

I'm trying to add the option to my users that, on a List Validator, to allow select any of the options or a blank option. Spreadjs has the IgnoreBlanks setting, which I use, so when the user uses the delete key or the backspace and deletes the cell it validates correctly.
However, I would love to use the same functionality as in Excel, which allows blank options in the list validator, in part of the list.
I've tried to target the <select> element that holds the list and programmatically add the empty element, however, it crashes after the user selects the empty option.
I've also tried to add different escaped characters to the list. If I select a character that represents an empty string or a tab, it won't add a new option to the list. If I use any strange character, or even the null character \0 you get a new option to select, but the content is that typical rectangle you see when your font doesn't have the character you're trying to display.
I've also tested using a regular ListValidator like in the example pages, not our custom functionality and doesn't work either.
https://www.grapecity.com/demos/spread/JS/TutorialSample/#/demos/basicDataValidator
I have also tried creating a FormulaListValidator, and if my range has empty cells I could then get an empty option on my list, however, because the range may have duplicates, I get duplicated options.
After researching a little bit I found a workaround in a different language which I adapted to Typescript (Angular 6)
export const getListValidatorFromArray = (spread: GC.Spread.Sheets.Workbook, data: any[]) => {
// saving validation list values in a hidden sheet
spread.addSheet(spread.getSheetCount());
const sheet = spread.getSheet(spread.getSheetCount() - 1);
sheet.visible(false);
for (let i = 0; i < data.length; i++) {
sheet.setValue(i, 0, data[i]);
}
// create validator based on the values
const dv = GC.Spread.Sheets.DataValidation.createFormulaListValidator(
'=' + sheet.name() + '!$A$1:' + sheet.name() + '!$A$' + data.length
);
return dv;
};
Note: This creates an extra sheet for each validator you create. Makes sure you reuse them as much as possible (i.e. assigning it to a variable when it's created, and reusing the variable for other columns/rows that use the same one).

1-indexed Model in QCombobox

I have a 1-indexed (readonly-)model and want to use it for a combobox.
I parse the data (comes from a file-parser) and have for example:
1: Variable Number 1 and that will be my first item, next
2: Variable Number 2 and so on.
When I click on an item the currentIndex()-method from QCombobox will give me a 0-indexed int, so my problem is:
I don't want to write everytime I parse a file +1 respectively -1 when writing back to the file (although the model is readonly, I can alter the data in the file). (I have nearly 30 UIs where I need the model, and for every UI I have to parse other data)
I currently use something like:
virtual int currentIndex() const { return QComboBox::currentIndex() + 1; }
virtual void setCurrentIndex(int index) { QComboBox::setCurrentIndex(index-1); }
I know that this is not ideal, because (set-)currentIndex is not virtual. But to avoid +/-1 I used this for now.
Does anybode have a good suggestion for this problem?
If you have a custom model you could add a role that returns the "real" index value.
If you just use strings to fill the combobox, you could use the setItemData() and itemData() methods to associated your reference value.
E.g.
comboBox->addItem("Number 1", 1);
and
int refValue = comboBox->itemData(comboIndex).toInt();
The associated data can be anything that can be stored in a QVariant.

In Google Sheets, how can I assign a number to an arbitrary value?

For example, how can I do something like:
=AVERAGE(TOINTIF(A1:A17, "Fifth", 5), TOINTIF(A1:A17, "Sixth", 6), [...])
, TOINTIF(range, query, value) being a function that takes all the values in a range that meet a condition and places them into an array of instances a specified number.
Can this be done in GSheets?
You really just need if statements - probably combined with arrayformula:
=sort(ARRAYFORMULA(if(A1:A17="Fifth", 5,)),1,true)
if you dont need them grouped together you can remove the sort and leave
=ARRAYFORMULA(if(A1:A17="Fifth", 5,))
to nest them:
=ARRAYFORMULA(if(A1:A17="Fifth", 5,if(A1:A17="Sixth", 6,))