How to format numbers in NativeScript? - nativescript

I have a lot of code for Google Sheets and now I start to use it in NativeScript. I know how to format numbers in Google Sheets but I didn’t find any similar options in component.
For example, my function return percent value, it is the number between 0 and 1. In Google Sheets I write code =myFunction(), then I select appropriate format for cell and it looks like 23.5%.
In NativeScript I’m using XML file and write
<Label text=“{{ myFunction }}”/>
But it shows 0.2358765 and I don’t find any options in NativeScript documentation how to properly format this number.
I’m not familiar with CSS, may be I have to use CSS? What command of CSS or NativeScript I have to use to format the numbers?

You should declare Converters either in your data model or in application module if you like to reuse the same often.
What you write in your converter totally depends on how you want to format your numbers. There are even NPM packages those support interpreting Excel Formulas, you might want to check them too.

You should be able to do something like this:
<Label text=“{{ (myVariable).toLocaleString('en-us', {minimumFractionDigits: 2}) }}”/>
These links will give you more details and a few different alternatives:
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/toLocaleString
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/NumberFormat
https://docs.nativescript.org/core-concepts/data-binding#using-converters-in-bindings

Related

how to create double range price slider using react bootstrap

How to create double range slider using react bootstrap
I tried with npm install react-bootstrap-range-slider
<RangeSlider
value={value}
onChange={changeEvent => setValue(changeEvent.target.value)}
/>
But it shows only one range i want two range look like this image:
Double range slider
react-bootstrap follows the specification of bootstrap. Bootstrap class "form-range" is only appliable to one input of type "range", which in turn only supports one value:
https://react-bootstrap.github.io/forms/range/#form-range-props
https://getbootstrap.com/docs/5.1/forms/range/#overview
https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input/range
So the answer is: it's not possible with built-in methods/properties.
Edit:
so how to manage this with double range slider? give me some
suggestion !
You asked how to do it "using react bootstrap" and this is exactly the answer to it.
Have you tried to google it? As always in the big programmer world, you have two possibilities:
Find and use third party solution
Write your own
For the first point I just googled and found https://zillow.github.io/react-slider/, which is capable of working with two values (they called thumbs). It is also unopinionated in terms of styling, so you can adjust bootstrap stylings/classes. Then it will look like a true bootstrap component.
For the second point: There are many minimalistic solutions. So just look for the one you like most and don't reinvent the wheel. For example you can take two sliders, that will look like one:
HTML5: Slider with two inputs possible?
Ho can I add two values in Bootstrap range slider
how to implement a price range slider

Passing Markdown Content to Ruby Function With Jekyll/Liquid

I am trying to write a jekyll plugin that will take a normal markdown file and provide some extra functionality on top of it. In particular, I need to do some (not actually) fancy things with tables. I know you can write straight HTML into a markdown file, but there is a requirement that the content folks don't want to / can't edit HTML.
As an extra wrench in the works, the mobile layout has a UX requirement that I essentially have to render the table as a group of divs as opposed to a table.
My initial thought was to pass the {{page.content}} variable to a ruby function extending Liquid::Tag. From there I was planning on parsing the markdown file and either:
1. If normal non-table markdown, use as normal
2. If table markdown, look for custom identifier in markdown, do what needs to be done (e.g. add class, etc)
If I do something like this:
def render(context)
content = Liquid::Template.parse(#markup).render context
end
It renders the context as a normal markdown file. However, I want to break up the context variable and work with the pieces before rendering. I've tried a few different approaches that I've gotten from the jekyll docs and Stack Overflow and gotten nowhere.
Does anyone have any experience with this? I am heading down the right path? For what it's worth, Ruby/Jekyll/Liquid is fairly new to me, so if you think I may have missed something fairly basic and obvious then please let me know.
A markdown table tool for editors !
markdownify your table in http://www.tablesgenerator.com/markdown_tables
paste the markdown result in http://prose.io/
done
I don't know other way to simplify editor's work on Jekyll, but I'll be very interested in earing from your project. Good luck.

CodeIgniter santizing POST values

I have a text area in which I am trying to add youtube embed code and other HTML tags. $this->input->post is converting the <iframe> tags to < and > respectively but not the <h1> and <h2> tags.
Any idea how I can store these values?
If you only have a small number of forms that you need to allow iframes in, I would just write a function to restore the iframe (while validating that it's a valid YouTube embed code).
You can also turn off global_xss_filtering in your config (or not implement it if you're using it), but that's not the ideal solution (turning off all of your security to get one thing to work is generally a horrible idea).
$config['global_xss_filtering'] = FALSE;
To see all of the tags that get filtered out, look in the CI_Input class and search for the '$naughty' variable. You'll see a pipe-delimited list (don't change anything in this class).
Why don't you avoid CIs auto sanitizing and use something like htmlspecialchars($_POST['var']); ? Or make a helper function for sanitizing youtube urls...
Or you could either just ask for the video ID code or parse the code from what you are getting.
This would let you use both the URL or the embed code.
Also storing just the ID takes less space in you database, and you could write a helper function to output the embed code/url.
In this case, use $_POST instead of $this->input->post to get the original text area value, and then use HTML Purifier to clean the contents without losing the <iframe> tag you want.
You will need to check HTML Purifier documentation for details. Please, check this specific documentation page about "Embedding YouTube Videos".

How to retrieve plain text from a formatted website to use in UIWebView

Not sure if what I want to do is possible, but what I am hoping to do is somehow gather certain pieces of text from a website, remove the header, footer, background, all formatting, and place it into my application in a scrollview or something similar...
I'll give you an example... Imagine I was making wikipedia's iPhone app, I want to download the information about the wiki on dogs, without the header, side bars etc, just the text. How would I go about doing this?
I understand that for this I have not provided any example code or what I've tried or started, but that's just because in this case I'm lost! That doesn't mean I want full chunks of code either. Any help will do. If this doesn't work, I will just have to make a 'mobile optimised' version of the webpages I want to include in my app.
Thanks
(Edit: the term I was trying to use was 'strip the web page of its HTML coding')
You may be going about this the wrong way, or perhaps even asking the wrong question.
Does the target website have an API or datafeed of some kind?
Can you get the information you need in JSON or XML format directly from the site?
I think you've misunderstood the technology. HTML is merely the framwork on which the formatting and data is hung.
Parsing the HTML page seems like an awfully big headache, I doubt you'll ever be able to get it to work, because almost all sites these days are partially or wholly generated on the server side, the page is only the result.
Some sites hide the information in memory and others get it dynamically through ajax for example, which means that simply trying to get the data by parsing the HTML will get zero data.
Another issue you should be aware of though, is that simply copying the data from generated websites may open yourself up to copyright issues.
You have to parse the html code and search for the part that you want and "throw" away the part that you do not need. This is more or less like bruteforcing and the code of the website should not change otherwise you are screwed. So you have to write the parser by hand with this method. But maybe there is a atom or rss feed and you can parse this one. This will be much more easier and you are not depending on the website layout because the rss/atom feed is just about the data. For parsing rss you could try out NSXMLParser.
And then you have to make a valid html page out of the data and present it in the UIWebView

Convert HTML form to PDF

How do I convert a html form to PDF. I would like to use Prawn for the purpose.
Pointing to any relevant links or examples would be very helpful.
Why would you want to limit yourself to a technology (Prawn) not appropriate to the task (it's not geared towards using HTML to generate the PDF)?
You might want to check out PDFKit instead, as it seems specifically designed to create PDFs from HTML, using powerful existing libraries.
Super short version (two lines!):
kit = PDFKit.new("http://google.com")
kit.to_file('/path/to/save/google.pdf')
Read more about it here:
http://thinkrelevance.com/blog/2010/06/15/rethinking-pdf-creation-in-ruby.html
Check out the RailsCast: http://railscasts.com/episodes/220-pdfkit

Resources