Use disabled input to display data - angularjs

To get a consistent look and feel of both input and output views I am trying to use an disabled input element to display model data/values.
The value is a calculated temperature value and has several decimal digits. Since that does not make sense from an engineer's point of view I want to limit the displayed decimal digits to a certain amount (let's say two digits, the displayed value does not need to be rounded).
Example:
calculated value: 123.123456
value to display: 123.12
I read around the Internet and found many suggestions using input's step attribute like
step=".01"
to limit the decimal digits. There seem to be many people doing it that way, but it does not work for me.
I think view and data model need to kept separated so adapting the model data (like converting the values to strings or using toFixed()) does not seem to be a nice solution. The view should be able to format the data itself, not changing the data model and should have reading access in this case only.
There is a filter for doing this when accessing model data through the {{ }} notation. But this does not seem to be applicable straight out of the way.
So, do you have any suggestions about limiting the decimal numbers?
For the sake of investigation and in order to provide a working sample code I created a Pen.

Related

How to convert XML array text items into numbers in ColdFusion?

I am having problems converting XML data into the appropriate data types using a function.
I have read in an XML file using XmlParse().
Within that there is an array which I loop around. <Cfloop array=#i.Task# index="t">
My understanding is that the items in this array are XML text. I can display all the items with CFoutput no problem. One item in the array (BaseLineColor) is a colour. #t.BaseLineColor# However this colour value is a single decimal integer number of varying length. I have worked out the maths to convert this decimal number into R,G,B decimal values. All good so far.
The problem is that if I try mathematical functions on BaseLineColor, then I get:
The value ?xml version="1.0" encoding="UTF-8"? BaseLineColor 255 /BaseLineColor cannot be converted to a number.
So OK I have tried a few methods to try and convert BaseLineColor to an integer but nothing works. Val() doesn't work. In fact I can't seem to convert it into any datatype.
For example, here is me trying to make it a string - same error:
<cfscript>
Strbaselinecolor=toString(t.BaseLineColor);
rdec=floor(Strbaselinecolor / 65536);
gdec=floor((Srtbaselinecolor - rdec * 65536)/256);
bdec=floor(Strbaselinecolor - rdec * 65536 - gdec * 256);
writeOutput("#t.baselinecolor#: #Strbaselinecolor# red #rdec#, green #gdec#, blue #bdec#")
</cfscript>
What function should I be using? Am I supposed to be pre-processing the XML in some way before I can refer to some of these values as integers?
There are a lot of values in the XML data which are numbers (some integers and some floating point numbers) and so it is not just about these items that are colours but a more general problem with using any XML data that is not text. I have tried to find some reference material on this but have not found anything relevant so far. Yet I'm guessing this is a common issue when reading in XML files.
Thanks in advance for any help.
The error message is correct. The code is trying perform mathematical operations on something that is not a number, despite the fact that it may appear to be one in a browser... You're probably getting tripped up by how browsers handle tag based code like xml.
This code (incorrectly) shows the value of t.BaseLineColor as a simple number 255
<cfscript>
t = xmlParse('<?xml version="1.0" encoding="UTF-8"?><BaseLineColor>255</BaseLineColor>');
writeOutput(t.BaseLineColor);
</cfscript>
Runnable Example
However, using a browser's "Inspect Element" tool, reveals the value is actually an xml string. Since browsers treat anything enclosed in < and > as html tags, which aren't rendered, only the number 255 is visible on screen.
writeDump() is more helpful here. It shows t.BaseLineColor as an xml node, and it's value is accessible through the xmlText attribute.
That simple value can be used in mathematical operations.
<cfscript>
t = xmlParse('<?xml version="1.0" encoding="UTF-8"?><BaseLineColor>255</BaseLineColor>');
result = t.BaseLineColor.xmlText / 65536 ;
writeOutput( result );
</cfscript>
Runnable Example

FieldType.Number is capping the edit value to 100, any value more than 100 is automatically changed to 100

I have been struggling with this issue for a while now. In popup edit of Shield UI all the values that are entered FieldType.Number seems to have a upper limit of 100. Every value more than 100 gets automatically changed to 100.
There seem to be only 4 types String, boolean, data & number. The number seems to limit the max to 100 on edit and add.Even any decimal values are being rounded off automatically and their website is not providing much help on the issue because demo grid views on website are showing similar behaviour
Fields("empNumber", fb => fb.Path("empNumber").Type(ShieldUI.AspNetCore.Mvc.DataSource.FieldType.Number))
I'm looking for a way to add values more than 100 as well as decimal point for prices. Any help or suggestions in this regard are much appreciated
I ran into the same issue. However I found the following workaround. I have set the grid fieldtype to string instead of number. When editing or creating the grid a javascript is started that calls the controller method through ajax call. In my controller method I take the "string" value and convert it to an int like so:
propertyOfModel = Convert.ToInt32(stringParameterFromGrid);
That works for me, let me know if you need more help.

Get selected values in a checkbox group in xpages

I have a checkbox group and I am trying to get the values ​​selected via SSJS, but so far I have not been successful. I've tried several syntaxes, such as:
document1.getItemValueArray ("nameField")
and
getComponent ("nameField") getSelectedValues ​​();
Does anyone know a way to get the selected values ​​from a checkbox group?
document1.getFirstItem("nameField").getValues() may be what you want. If it's one value, it will be a string, not a Vector, which may be a problem with getItemValueArray().
With ODA (OpenNTF Domino API), we extended the getItemValue() method to take a second parameter and cast the result to that kind of object. That has a big benefit for this kind of scenario, allowing getItemValue("nameField", ArrayList.class) to always return an ArrayList even for a single value, plus ArrayList is a much better and more modern Java (so relevant also for SSJS) construct than a Vector.

xtype: numberfield value is going to auto correct(change) for more than 16 digit value

can any one explain why(how) the xtype: numberfield value is going to auto correct(change) if am providing more than a 16 digits value.
For Example:
22222222222222222 is changed to 22222222222222224
222222222222222222 is changed to 222222222222222200
2222222222222222222 is changed to 2222222222222222300
22222222222222222222 is changed to 22222222222222220000
222222222222222222222 is changed to 222222222222222230000
2222222222222222222222 is changed to 2.2222222222222222e+21
22222222222222222222222 is changed to 2.2222222222222223e+22
Which results in my page after rendering as shown below when get the value through in my component jsp page
NumberFieldTestValue:<%= properties.get("numberfieldname","") %>
Resulting as below
NumberFieldTestValue: 2.2222222222222223e+22
The problem
This behavior is caused by the fact that the dialog behavior is implemented in JavaScript. The numbers you're having problems with cannot be represented in it.
The language conforms to the ECMASCRIPT 5.1 specification.
To quote the Number type description
all the positive and negative integers whose magnitude is no greater
than 2^53 are representable in the Number type
The base 2 logarithm of 2222222222222222222222 is about 70, which means the number exceeds the maximum value. Hence your problems.
All in all, if you check your examples in a plain JS console in a browser, the same behavior will be displayed so this is not really a CQ problem.
Solution 1 - use a different type
To avoid this, you could potentially use xtype="textfield" and validate it against a regular expression to see if it consists of numbers only. Then you'd have to make sure to use a type capable of holding such numbers at the backend (like BigInteger).
The field could look like this:
<numberOfSandGrains
jcr:primaryType="cq:Widget"
fieldLabel="Number of grains of sand at the beach"
name="./grainsCount"
regex="/\d+/"
regexText="Please enter a numeric value."
xtype="textfield"/>
Solution 2 - change scale
Another option is to change the logic behind the configuration and use some different units if applicable. For instance, if the value 2222222222222222222222 is a number of grams (weight of an object/substance), it makes perfect sense to read it in metric tons instead (at least in many cases). The author could probably do without entering such humongous numbers.
You'll need to be extra-careful if you go this way.

pybrain image input to dataset for Neural Network

I'm trying to write a neural network that (after being properly trained) identifies certain road signs and returns a different output for each type of sign.
Before I started to train my network, I noticed on the pybrain website that their datasets are always an array of values, each entry containing an input and a target. The images I have for my NN have been converted to grayscale pixel data (a simple array of numbers). To train each set of data, do I need to somehow add a target value for each pixel? And if so, how would I go about doing that?
QUICK ANSWER
No, you don't need target for every single pixel, you treat pixels from single image as your input data and you add target to that data.
LONG ANSWER
What you trying to do is to solve classification problem. You have image represented by array of numbers and you need to classify it as some class from limited set of classes.
So lets say that you have 2 classes: prohibitions signs (I'm not native speaker, I don't know how you call signs that forbid something), and information signs. Lets say that prohibition signs is our class 1 and information signs is class 2.
Your data set should look like this:
([representation of sign in numbers], class) - single sample
After that, since it's classification problem, I recommend using _convertToOneOfMany() method of DataSet class, to convert your targets into multiple outputs.
I've answered similar question here, go check it out.

Resources