I want to handle emoji for 3 points.
1- Represent Emoji: I have functionality where user enter in Entry(textbox) and I show it in Label. Currently I use Label control to display text. I want to show Emoji selected by user in Label. If I try to show that emoji in label, it shows ??. Do I need to set any property to represent symbol or I need to change control? If I need to change control, which control I should use.
2- Pass Emoji in API: I want to save user entered text. Currently I only save text to database using API. I want to save emoji but I don't know how to get encoded character of emoji. Please note that I will get saved text from API to display in label. So, I must be able to get it from API and represent it.
Please suggest. Thank you
1- Represent Emoji
This is an easy task - you don't have to do anything special as you can just do:
<Label x:Name="lbl" Text="{Binding Source={x:Reference Name=ent}, Path=Text" />
<Entry x:Name="ent" />
or
lb.Text = ent.Text;
emoji should appear correctly in the Label.
2- Pass Emoji in API
This can be tricky, it may break JSON deserialization and etc. But it all depends on your setup. Try to send it to the API and try to retrieve it back. If there will be some problems check the next threads to get a better idea:
how can I Deserialize emoji in json in C#
How do I remove emoji characters from a string?
and etc.
Related
I am trying to figure out how to make the replacement parts fields data show up in all uppercase when the email is received. This form will be used for entering serial numbers containing alphanumeric characters which makes it hard to read when lowercase letters are used.
Is there an override that can accomplish this or will the mailer template need to be modified? How would you resolve this?
Assuming the field has the id 'replacement-parts', add a custom script adapter with the key code:
request.form['replacement-parts'] = request.form.get('replacement-parts', '').upper())
Make sure it's above your mailer, as the action adapters are executed in folder-contents order.
I have a form where use enters multiple line of texts in a text area.
Some of the lines can have html markups as well. Say one line is bold.
How should I save the text in my database?
Should I store them as like this?
This is a greap post
<br/>
I love this type of findings.
<br/>
<br/>
Thanks for sharing
OR like this?
This is a greap post
<br/>
I love this type of findings.
<br/>
<br/>
Thanks for sharing
During editing:
I must show the text as they were entered. So line break will be replaced by new line
That way use sees there is a line break. Textarea won't unserstand br markup
During displaying:
I must render the text so that it appears like this on the page:
This is a greap post
I love this type of findings.
Thanks for sharing
I want to know the cleanest way to store text that can have markup in them.
Thanks for help
Since you want to output HTML, you will have to store the input in it's raw format in the database. There is only one catch though. You never should trust input, since all input is evil, especially in this case, since outputting HTML directly as it is inputted, opens the possibility of an cross-site scripting (XSS) attack.
You have basically got two options:
Use a HTML sanitizer that let's you remove all tags that are not known to be safe. A good sanitizer is the one that comes with the Microsoft AntiXss toolkit.
Encode the input and decode parts of the result that are known to be safe, for instance:
string[] safeList = { "<br/>", "<b>", "</b>", "<i>", "</i>" };
public static string EncodeInputWithSafeList(string unsafeInput)
{
// First: encode the complete input.
string safeInput = Encoder.HtmlEncode(unsafeInput);
// Next: decode each tag that is known to be safe.
foreach (string safeTag in safeList)
{
string encodedTag = Encoder.HtmlEncode(safeTag, false);
safeInput = safeInput.Replace(encodedTag, safeTag);
}
return safeInput;
}
Note: The example uses the Encoder class from the Microsoft AntiXss toolkit.
Now the question becomes, at what point should we clean it up. Normally you should encode the output just before you send it to the client and not store it encoded in the database, since it depends on the output type (HTML, PDF, JSON) how data should be encoded. This is amplified by the fact that in case there is a bug in the encoder, there is no way to fix it, since the data is already encoded.
In this case it is a bit more tricky though, since the input is HTML and not just text. I would say that sanitizing is something you still would want to do before hand, because this way you prevent bad input from entering your database. The EncodeInputWithSafeList method is a bit tricky, because it is both a sanitizer and an encoder. When we run it before it goes into the database, it prevents the output from changing when we change the safe list. This can be both a good thing and a bad thing, but I would say that when you add new tags to the safe list, you wouldn't want old data to suddenly change. So in this case I would go with input encoding, instead of output encoding.
When you go with input encoding, name the database column in such way that it is clear that we're dealing with sanitized, encoded data.
Try htmlentities($str, ENT_QUOTES); before you save the data, and html_entity_decode($str) after you fetch it from your db, before you render it to the browser.
saving it to your database like this:
<p>This is a greap post
<br/>
I love this type of findings.
<br/>
<br/>
Thanks for sharing</p>
would work..
in my flex application i want to keep a format like...
i want to show space in client side while entering phone numbers..
After entering three numbers cursor should leave a space...
for eg:- 111 111111
is there any idea to work this in CLIENT SIDE itself
You can use Masked TextInput component. More info is here.
You should be able to work something out using the mx:PhoneFormatter (which can be customized to match whatever pattern you'd like): http://livedocs.adobe.com/flex/3/html/help.html?content=formatters_2.html
<mx:PhoneFormatter formatString="### ######" />
Perhaps replace the contents of the input field with the PhoneFormatted version onKeyUp.
What I need
ok I googled this and there are many tutorials on how to get the charCode from the character but I cant seem to find out how to get the character from the charcode.
Basically I am I am listening for the KeyDown event on a TextInput.
I prevent the char from being typed via event.preventDefault();
Later I need to add the text-char to the TextInput.
I can get the charCode via event.charCode so if I can turn that into a string I can save it for later user.
Why I need it
Basically I am making a TextInput, that that I can set to display default text in it. When A user types into it, I want to remove the default text first then add the user typed text.
Currently I am either removing it all, or ending up with both.
It's simple:
var yourNewChar:String = String.fromCharCode(event.charCode);
I need your advice with converting plain text to an URL.
The scenario will be this: The user will select some entry and then click a "convert to link" button.
The entry text the user selected will convert to (link: selected_text). I do it with JavaScript. And after that, when he clicks the Save button to save all his entry, I don't know how to store (link: selected_text) in tha database.
The URL will be like this: www.mysite.aspx?t=selected_text.
I can convert (link: selected_text) by using replace function in code-behind. But then I don't know how to show user as clickable and also by not showing <a href="www.mysite.aspx?t=selected_text">
It can be difficult to understand therefore I will show some of my codes to explain.
Private Sub Save(ByVal Entry As String) ' Entry Comes from entry textbox '
Dim elected As String
selected = Entry.Replace("(link: ", "<a href http://www.mysite.com?link=")
selected = Entry.Replace(")", ">")
' then here starts save but not necessary to show '
End Sub
If you must save processed input for some reason
(link: here)
must be converted to
(link: here)
To store in database, you'll have to track the changes separately somehow and post them back to the server. I'd suggest a HiddenInput control.
Do not save it as www.mysite.com?t=here. Just save the entry as the user types it. While showing it to user later, convert the "(link: here)" to link and show that.
Save the post as the user wrote it. This will make it easier to allow editing of the post later. When you render the message you should use a regular expression to replace it with a real link. You should never replace all ")" with ">". What happends if i write "hello (world)"?
The result:
Hello (world>
You can find great regular expressions here:
http://regexlib.com