I need to mimic a web/browser based piece of functionality where a blur event is used to trigger some post entry-field handling.
However using a TextField with Nativescript I only have the "returnPress" event (as far as I can see from the UITextFieldDelegateImpl class source). This event works but is not what I need.
There is some interesting code in there though, especially the textFieldDidEndEditing method:
public textFieldDidEndEditing(textField: UITextField) {
let owner = this._owner.get();
if (owner) {
if (owner.updateTextTrigger === UpdateTextTrigger.focusLost) {
owner._onPropertyChangedFromNative(TextBase.textProperty, textField.text);
}
owner.dismissSoftInput();
}
}
It looks like this should be the place to fire a blur event but maybe there is some other way to accomplish what I need without messing with the framework code.
I did a little research and found that you could use Observable.propertyChangeEvent and the GestureModule. The next code snippets showcase the mentioned approach.
main-page.xml
<Page xmlns="http://schemas.nativescript.org/tns.xsd" navigatingTo="navigatingTo" loaded="loaded">
<StackLayout id="stack">
<Label text="Test" textWrap="true" id="label"/>
<TextField returnKeyType="done" updateTextTrigger="focusLost" hint="text" id="textfield" text="{{ textfield }}" autocorrect="false" autocapitalizationType="none" />
<TextField hint="test2" text="{{ }}" id="textfield2"/>
</StackLayout>
</Page>
main-page.js
var observable_1 = require("data/observable");
var gestures_1 = require('ui/gestures');
var textFieldEmail;
function loaded(args) {
var page = args.object;
var textField = page.getViewById("textfield");
var stackLayout = page.getViewById("stack");
var observable = new observable_1.Observable();
observable.addEventListener(observable_1.Observable.propertyChangeEvent, function (pcd) {
console.log(pcd.eventName.toString() + " " + pcd.propertyName.toString() + " " + pcd.value.toString());
});
stackLayout.on(gestures_1.GestureTypes.tap, function (args) {
console.log("Tap");
if (page.ios) {
textField.ios.resignFirstResponder();
}
else {
textField.android.clearFocus();
}
});
page.bindingContext = observable;
}
exports.loaded = loaded;
Related
enter image description herethis problem show in ios,when i use TextInput of react-native,but it can't type Chinese when using soft keyboard,so i modify the code like picture1,but a new problem has arisen,when i enter the key to send ,the value of the TextInput cant clear.
what can i do?enter image desenter code herecription here
<TextareaItem clear={true} type="text" ref="text" value={this.state.meg}
editable={true} disabled={false} onChange={(value) => {
if (Platform.OS =='ios'){
this.meg = value
} else {
this.setState({
meg:value
})}}} />
sendMeg = () => {
let message = ''
if (this.meg !== '')
messahe = this.meg
}else{message = this.state.meg}
this.meg = ''
this.setState({ meg:''})
}
solve with this answer https://github.com/CHANOMA/react-native/pull/3/files#diff-8eb50d68d87e28556c034717cd58a86e
Set this.state.text to initially be an empty string ‘’
Add an actual placeholder to your component and set the value to the string ‘Enter text…’
Add the method submitAndClear to your class and set the component’s onPress prop to this.submitAndClear
Add the prop clearButtonMode='always’ to the <TextInput /> component — this will give you an option to clear the text at any time
The following can be used to clear the text
submitAndClear = () => {
this.props.writeText(this.state.text)
this.setState({
text: ''
})
}
You're good to go!!
Add this code where you want to reset meg field:
this.setState({meg: ''})
I have been using SaveToString() method to get the source code of the page in WebBrowser Control. But since its been deprecated in Windows 10, Whats the equivalent for SaveToString() in WebView Control of Windows 10.
WebView allows us to invoke script, and we can dump the document.documentElement.outerHTML to do the same thing as SaveToString().
The following shows a very simple sample for your test. Note that I didn't try to make a cool UI design and make all things formatted, but only try to show you the idea.
In xaml:
<StackPanel>
<WebView x:Name="MyWebView" Source="http://www.bing.com" Height="200"
DOMContentLoaded="MyWebView_DOMContentLoaded"/>
<Button x:Name="ViewSourceBtn" Content="View Source" Click="ViewSourceBtn_Click"/>
<RichTextBlock x:Name="SourceBlock" Height="300" >
</RichTextBlock>
</StackPanel>
Code behind:
bool contentloaded = false;
private async void ViewSourceBtn_Click(object sender, RoutedEventArgs e)
{
if (contentloaded)
{
string html = await MyWebView.InvokeScriptAsync("eval", new string[] { "document.documentElement.outerHTML;" });
var paragraph = new Paragraph();
paragraph.Inlines.Add(new Run { Text = html });
SourceBlock.Blocks.Clear();
SourceBlock.Blocks.Add(paragraph);
}
else
{
string err = "Waiting for HTML content to load!";
var paragraph = new Paragraph();
paragraph.Inlines.Add(new Run { Text = err });
SourceBlock.Blocks.Clear();
SourceBlock.Blocks.Add(paragraph);
}
}
private void MyWebView_DOMContentLoaded(WebView sender, WebViewDOMContentLoadedEventArgs args)
{
contentloaded = true;
}
Here is the result by clicking view source button:
I can't find any up to date documentation on this scenario, and it's really frustrating.
I have tel:555-555-5555 links and mailto:johndoe#555.com and I want to track each click separately.
Should I add two of these snippets, one for each type? I noticed there is a "Conversion_Label" field, so I assume I should?
<script type="text/javascript">
/* <![CDATA[ */
goog_snippet_vars = function() {
var w = window;
w.google_conversion_id = XXXXXXXXX;
w.google_conversion_label = "XXX1";
w.google_remarketing_only = false;
}
// DO NOT CHANGE THE CODE BELOW.
goog_report_conversion = function(url) {
goog_snippet_vars();
window.google_conversion_format = "3";
window.google_is_call = true;
var opt = new Object();
opt.onload_callback = function() {
if (typeof(url) != 'undefined') {
window.location = url;
}
}
var conv_handler = window['google_trackConversion'];
if (typeof(conv_handler) == 'function') {
conv_handler(opt);
}
}
/* ]]> */
<script type="text/javascript"
src="//www.googleadservices.com/pagead/conversion_async.js">
</script>
From here, now Google just says to add the onClick handlers but they are the same other than the link inside:
<a onclick="goog_report_conversion
('http://www.example.com/whitepapers/a.pdf')"
href="#" >DOWNLOAD NOW</a>
<a onclick="goog_report_conversion
('tel:555-555-5555')"
href="#" >CALL NOW</a>
Will Google tell the difference between the two click events?
Thanks for any advice!
No, there will be no difference between the two click events.
This is my workaround:
Setup one additional conversion code (for the download conversion). The difference from the first conversion code will be only in this line w.google_conversion_label = "XXX2";
Next change the line of the new code from goog_snippet_vars = function() { to goog_snippet_varsD = function() {
Next change the line of the new code from goog_report_conversion = function(url) { to goog_report_conversionD = function(url) {. Don't mind the warning // DO NOT CHANGE THE CODE BELOW. :)
Next change the line of the new code from goog_snippet_vars(); to goog_snippet_varsD(); Don't mind the warning // DO NOT CHANGE THE CODE BELOW. :)
Last change - from:
<a onclick="goog_report_conversion
('http://www.example.com/whitepapers/a.pdf')"
href="#" >DOWNLOAD NOW</a>
to
<a onclick="goog_report_conversionD
('http://www.example.com/whitepapers/a.pdf')"
href="#" >DOWNLOAD NOW</a>
Voila! Now you are ready to track two conversion actions in one page.
I want to open a new window, configured with height and width, all while using < h:commandLink >
<h:commandLink id="zyzid" value="click me" action="#{test.testDo}" target="_blank" />
this renders into:
<a onclick="mojarra.jsfcljs(document.getElementById('myForm'),{'myForm:xyzid':'myForm:xyzid'},'_blank');return false" href="#" id="myForm:xyzid">click me</a>
I looked at jsfcljs() function. It submits the form with target="_blank", but i don't see window.open() anywhere. So, how would I be able to alter this code to change new window's height and width?
for reference:
mojarra.jsfcljs = function jsfcljs(f, pvp, t) {
mojarra.apf(f, pvp);
var ft = f.target;
if (t) {
f.target = t;
}
f.submit();
f.target = ft;
mojarra.dpf(f);
};
I found a few relevant links, and this and I arrived at this solution, which seems to work for me. h:commandLink opens a new page, and I get to manipulate it's width and height. This involves slightly modifying/overwriting the mojarra.jsfcljs function. It opens a window with standard window.open() (triggered by onclick) and associates the form it is submitting with that window.
$(window).load(function(){
mojarra.jsfcljs = function jsfcljs(f, pvp, t) {
mojarra.apf(f, pvp);
var ft = f.target;
if (t) {
if (t.indexOf('options') != -1){
f.target = '_blank' + new Date().getTime();
var options = t.substring(t.indexOf('optionts') + 9);
window.open('', f.target, options);
}
else{
f.target = t;
}
}
f.submit();
f.target = ft;
mojarra.dpf(f);
};
});
markup:
< h:commandLink id="viewLink" action="#{testBean.doTest}" value="h:commandLink" target="options:height=200, width=300" />
I want to have a "Restore defaults" button in my extension's preferences window:
<prefpane id="nextplease.phrases" label="&options.phrases.title;"
image="chrome://nextplease/skin/Document.png">
<preferences>
<preference id="nextphrases" name="nextplease.nextphrase.expr0"
type="unichar"/>
...
</preferences>
<hbox flex="1">
...
<listbox id="nextphrases_list" seltype="multiple" flex="1"
onkeypress="nextplease.removeSelectedOnDelete(event, this);"
onselect="nextplease.enableDisableRemoveButton(this);"
preference="nextphrases" preference-editable="true"
onsynctopreference="return nextplease.syncListbox(this);"
onsyncfrompreference="nextplease.loadListboxPreference(this);"/>
...
<button label="&options.restoreDefault;"
oncommand="nextplease.restoreDefaultListbox(this);" />
</hbox>
</vbox>
</hbox>
</prefpane>
This is the JavaScript code for the functions:
nextplease.restoreDefaultListbox = function (node) {
var listbox = node.parentNode.parentNode.firstChild.selectedPanel;
var preferenceId = listbox.getAttribute("preference");
var preference = document.getElementById(preferenceId);
preference.reset();
alert("preference.value="+preference.value+"; preference.valueFromPreferences="+preference.valueFromPreferences);
preference.setElementValue(listbox);
};
nextplease.loadListboxPreference = function (listbox) {
var i, phrase, values;
var preferenceId = listbox.getAttribute("preference");
var preference = document.getElementById(preferenceId);
var prefValue = ??? // neither preference.value nor preference.valueFromPreferences work, see below
// alert("Loading: "+prefValue);
// remove all items already in listbox
for (i = listbox.itemCount; i >= 0; i--) {
listbox.removeItemAt(i);
}
values = prefValue.split("|");
for (i = 0; i < values.length; i++) {
phrase = values[i].replace(/&pipe;/g, "|");
if (phrase !== "") {
listbox.appendItem(phrase, phrase);
// Scroll to the newly added item to workaround
// what I think is a Firefox bug. I was getting
// Javascript exceptions when trying to read the
// values at the bottom that are "hidden".
listbox.ensureIndexIsVisible(listbox.getRowCount() - 1);
}
}
listbox.ensureIndexIsVisible(0);
};
Now, when I click on the button, the alert I get (after preference.reset()) looks like this:
preference.value=undefined; preference.valueFromPreferences=old user-set preference value
So it seems like in onsyncfrompreference the correct preference value can't be accessed except in a really ugly way:
if (preference.value === undefined) {
prefValue = preference.preferences.defaultBranch.getIntValue(preference.name); // or other type instead of Int
} else {
prefValue = preference.value;
}
Is there a better alternative? Specifically, one which would work for any preference type?
If pref.value === undefined, you should use pref.defaultValue to get the value to display. I updated the reference page and the onsyncfrompreference documentation to say that.