set the default value of TextField inside alertDialog - appcelerator

i found the following sample code from Appcelerator's docs (http://docs.appcelerator.com/platform/latest/#!/api/Titanium.UI.AlertDialog-property-previewContext):
var dialog = Ti.UI.createAlertDialog({
title: 'Enter text',
style: Ti.UI.iOS.AlertDialogStyle.PLAIN_TEXT_INPUT,
buttonNames: ['OK']
});
dialog.addEventListener('click', function(e){
Ti.API.info('e.text: ' + e.text);
});
dialog.show();
The problem is that i need to set a default value for the input text, but the documentation only shows the possibility to set a placeholder, but not a default value for it.

If you are building for Android, you can use androidView property to add a custom View that contains the TextField. Then you can set value of the TextField to whatever your default value is.
For iOS, I don't know any way to achieve your goal other than making your own alert dialog. Perhaps there are some modules for this.

For iOS , Actually you can`t
you can see the code of TiUIAlertDialogProxy.m
https://github.com/appcelerator/titanium_mobile/blob/master/iphone/Classes/TiUIAlertDialogProxy.m#L164
There is no TextField value
if ( (style == UIAlertViewStylePlainTextInput) || (style == UIAlertViewStyleSecureTextInput) ) {
[alertController addTextFieldWithConfigurationHandler:^(UITextField *textField) {
textField.secureTextEntry = (style == UIAlertViewStyleSecureTextInput);
textField.placeholder = [TiUtils stringValue:[self valueForKey:#"placeholder"]] ?: #"";
textField.keyboardType = [TiUtils intValue:[self valueForKey:#"keyboardType"] def:UIKeyboardTypeDefault];
textField.returnKeyType = [TiUtils intValue:[self valueForKey:#"returnKeyType"] def:UIReturnKeyDefault];
textField.keyboardAppearance = [TiUtils intValue:[self valueForKey:#"keyboardAppearance"] def:UIKeyboardAppearanceDefault];
}];
}
but you can make it manually , add this code
textField.text = [TiUtils stringValue:[self valueForKey:#"text"]] ?: #"";
then pass text property
var dialog = Ti.UI.createAlertDialog({
text:'Init text',
title: 'Enter text',
style: Ti.UI.iOS.AlertDialogStyle.PLAIN_TEXT_INPUT,
buttonNames: ['OK']
});

You can set the value, loginValue and passwordValue properties to the alert-dialog using Titanium SDK 6.1.0 and later!

Related

Is "cancel" a keyword or reserved word in Photoshop?

Is "cancel" a keyword or reserved word?
My simple dialog box:
var dlg = new Window("dialog");
dlg.text = "Proceed?";
dlg.preferredSize.width = 160;
// GROUP1
// ======
var group1 = dlg.add("group", undefined, {name: "group1"});
group1.preferredSize.width = 160;
// add buttons
var button1 = group1.add ("button", undefined);
button1.text = "OK";
var button2 = group1.add ("button", undefined);
button2.text = "Cancel";
var myReturn = dlg.show();
if (myReturn == 1)
{
// code here
}
Works fine. All is well. However replace the string "Cancel" with "Can" and the button no longer functions.
You need to add extra code in order to regain functionality.
button2.onClick = function()
{
// alert("Byas!");
dlg.close();
dialogResponse = "cancel";
}
So, what's going on, is "cancel" a keyword?
"Cancel" is not a reserved word. If you change it to can, the dialog will return "can" if clicked (and not "cancel"). Maybe you need to update your code somewhere else to reflect it.
It works with your extra code because you're forcing the return of "cancel".

Copy cell from Interactive Grid Oracle Apex

I'm trying to copy a specific cell from an Interactive Grid (which is in Display Only mode, if that matters), and instead of copying the cell I'm in, I'm copying the whole row. I can't seem to find any way to copy just the cell.
APEX versiĆ³n: Application Express 19.1.0.00.15
Thank you beforehand.
Oracle Apex does not enable copy functionality to interactive report by purpose.
To enable it, you need to use even handler for copy event. This handler should be on the body or document. It can be achieved through Dynamic Action :
Event: Custom
Custom Event: copy
Selection Type: jQuery Selector
jQuery Selector: body
Then add one JavaScript true action with below code:
var text, i, selection, gridSel;
var event = this.browserEvent.originalEvent; // need the clipboard event
// we only care about copy from a grid cell ignore the rest
if ( !$(document.activeElement).hasClass("a-GV-cell") ) {
return;
}
var view = apex.region("emp").widget().interactiveGrid("getCurrentView"); //change "emp" to you IG static id
if ( view.internalIdentifier === "grid") {
text = "";
selection = window.getSelection();
gridSel = view.view$.grid("getSelection");
for (i = 0; i < gridSel.length; i++) {
selection.selectAllChildren(gridSel[i][0]);
text += selection.toString();
if (gridSel[i].length > 1) {
selection.selectAllChildren(gridSel[i][1]);
text += " \t" + selection.toString();
}
text += "";
}
selection.removeAllRanges();
event.clipboardData.setData('text/plain', text);
event.preventDefault();
}
The above will copy the current grid selection to the clipboard when the user types Ctrl+C while in a grid cell.
I wonder if the below javascript can be modified in order to trigger 'toggle' actions of interactive grid such 'selection-mode'.
apex.region( "[region static ID] " ).call( "getActions" ).lookup( "[action name]" );
Reference:
https://docs.oracle.com/en/database/oracle/application-express/20.1/aexjs/interactiveGrid.html
If someone is interested, I managed to find the solution.
Go on Interactive Grid's attributes--> JavaScript Initialization Code
and add the following code that creates a button that copies the selected cell.
function(config) {
let $ = apex.jQuery,
toolbarData = $.apex.interactiveGrid.copyDefaultToolbar(),
toolbarGroup3 = toolbarData.toolbarFind("actions3");
toolbarGroup3.controls.push({type: "BUTTON",
label: "Copy cell",
icon: "fa fa-copy is-blue",
iconBeforeLabel: true,
iconOnly: false,
disabled: false,
action: "custom-event" // instead of specific action eg "selection-copy", create a custom event
});
config.initActions = function( actions ) {
actions.add( {
name: "custom-event",
action: function(event, focusElement) {
actions.lookup('selection-mode').set(false); // select cell instead of the whole row
apex.region( "users_id" ).widget().interactiveGrid( "getActions" ).invoke( "selection-copy" ); // copy the selection
actions.lookup('selection-mode').set(true); // select again the whole row (important in case of master-detail grids)
}
} );
}
config.toolbarData = toolbarData;
return config;
}

Change the color of the dialog buttons in iOS?

Is there a way to change the text color of the dialog buttons in iOS?
I mean for the OK/Cancel buttons at the bottom for the alerts/confirm dialogs etc.
If native code, that's ok also.
You will be needing to use native code if you want to achieve this on IOS, here's how you can do it:
if (isIOS) {
var alertController = UIAlertController.alertControllerWithTitleMessagePreferredStyle("title", "message", UIAlertControllerStyle.ActionSheet);
// Here are some premade styling. The destructive by default is red on IOS. You can select default for them all or use existing.
var editAction = UIAlertAction.actionWithTitleStyleHandler("Edit", UIAlertActionStyle.Default, (arg: UIAlertAction) => {
//code implementation here
});
var deleteAction = UIAlertAction.actionWithTitleStyleHandler("Delete", UIAlertActionStyle.Destructive, (arg: UIAlertAction) => {
//code implementation here
});
var cancelAction = UIAlertAction.actionWithTitleStyleHandler("Cancel", UIAlertActionStyle.Cancel, (arg: UIAlertAction) => {
//code implementation here
});
alertController.addAction(editAction);
alertController.addAction(deleteAction);
alertController.addAction(cancelAction);
// This is how you can force change the color of the title text on the actions (buttons).
alertController.view.tintColor = new Color("#FF0000").ios; // Color is a class in Nativescript, if we you want the Native IOS value, this is how you do it.
var currentPage = topmost().currentPage;
var viewController: UIViewController = currentPage.ios;
viewController.presentModalViewControllerAnimated(alertController, true);
}
Make sure you imported what's needed:
import { isIOS, Color } from 'tns-core-modules/ui/page/page';
import { topmost } from 'tns-core-modules/ui/frame';
There are other styling customizations you can do by changing the default alertController.view settings. So just try out what's best for your use case.

CKEDITOR READONLY enable other buttons

I have a problem.
When I make the editor 'readonly' some of the buttons (copy, preview, full screen) stay enabled.
Normal
Select some text
How I can enabled other buttons when I select the text? (for example enabled button 'BGColor')
You can do something like this
Look for selection event.
CKEDITOR.instances["textarea"].on( 'selectionChange', function( evt ) {
// get desired command from ckeditor
var myCommand = this.getCommand( 'CKEDITOR_COMMAND_NAME' );
var mySelection = null;
// check if something is selected
var mySelection = this.getSelection().getNative() || this.window.$.getSelection() || this.document.$.selection;
if (!mySelection) {
// if not stay disable
myCommand.disable();
} else {
//if yes enable command
myCommand.enable();
}
});

Disabling specific button in ToolBar while cursor is in the editable portion of a widget? (CKEditor version 4.5.11)

I am wondering if it is possible to disable a specific widget in the ToolBar in the 'editables' portion of the widget code? I currently have the below code set up for a widget. Within these selectors, I do not want the user adding in a specific widget in the ToolBar.
this.editables = {
content1: {
selector: '.content1',
allowedContent: this.allowedContent
},
content2: {
selector: '.content2',
allowedContent: this.allowedContent
},
content3: {
selector: '.content3',
allowedContent: this.allowedContent
}
};
I have tried adding in the below logic but it breaks my code.
var oWidget= editor.getCommand('customWidget')
oWidget.setState(CKEDITOR.TRISTATE_DISABLED);
Any advise would be much appreciated.
Thank you!
For this you need to check for user selection event, and if selection in editable portion enable command.
Something like this -
CKEDITOR.instances["textarea"].on( 'selectionChange', function( evt ) {
// get desired command from ckeditor
var myCommand = this.getCommand( 'CKEDITOR_COMMAND_NAME' );
var mySelection = null;
// check if something is selected
var mySelection = this.getSelection().getNative() || this.window.$.getSelection() || this.document.$.selection;
if (!mySelection) {
// if not stay disable
myCommand.disable();
} else {
//if yes enable command
myCommand.enable();
}
});

Resources