How to pass a var from one page to another in blackberry 10 cascades? - blackberry-10

How to pass a data (ex userid ) from one page to another page in blackberry 10 qml ?

You can either create property on target page or create a java script function to do so. If you want to validate or perform any other operation before assigning you should use java script function.
Page {
//targetPage
property string userid //you can also use alias here
function initialize(id) {
userid = id
//you can also set property of controls here
}
}
Call it on your page like this
targetPageid.userid = "user id"
OR
targetPageid.initialize("user id")

Create an object in your cpp
qml->setContextProperty("MyApp",this);
And then call the method using this object. i called a method in a button in my main.qml
Button{
id : button
text : "Connect"
onClicked:
{
MyApp.PostData("46565652","sotho")
}
horizontalAlignment: HorizontalAlignment.Center
}

Related

Get newly created id of a record before redirecting page

I would like to retrieve the id of a newly created record using javascript when I click on save button and just before redirecting page.
Do you have any idea please ?
Thank you !
One way to do this in Sugar 7 would be by overriding the CreateView.
Here an example of a CustomCreateView that outputs the new id in an alert-message after a new Account was successfully created, but before Sugar gets to react to the created record.
custom/modules/Accounts/clients/base/views/create/create.js:
({
extendsFrom: 'CreateView',
// This initialize function override does nothing except log to console,
// so that you can see that your custom view has been loaded.
// You can remove this function entirely. Sugar will default to CreateView's initialize then.
initialize: function(options) {
this._super('initialize', [options]);
console.log('Custom create view initialized.');
},
// saveModel is the function used to save the new record, let's override it.
// Parameters 'success' and 'error' are functions/callbacks.
// (based on clients/base/views/create/create.js)
saveModel: function(success, error) {
// Let's inject our own code into the success callback.
var custom_success = function() {
// Execute our custom code and forward all callback arguments, in case you want to use them.
this.customCodeOnCreate(arguments)
// Execute the original callback (which will show the message and redirect etc.)
success(arguments);
};
// Make sure that the "this" variable will be set to _this_ view when our custom function is called via callback.
custom_success = _.bind(custom_success , this);
// Let's call the original saveModel with our custom callback.
this._super('saveModel', [custom_success, error]);
},
// our custom code
customCodeOnCreate: function() {
console.log('customCodeOnCreate() called with these arguments:', arguments);
// Retrieve the id of the model.
var new_id = this.model.get('id');
// do something with id
if (!_.isEmpty(new_id)) {
alert('new id: ' + new_id);
}
}
})
I tested this with the Accounts module of Sugar 7.7.2.1, but it should be possible to implement this for all other sidecar modules within Sugar.
However, this will not work for modules in backward-compatibility mode (those with #bwc in their URL).
Note: If the module in question already has its own Base<ModuleName>CreateView, you probably should extend from <ModuleName>CreateView (no Base) instead of from the default CreateView.
Be aware that this code has a small chance of breaking during Sugar upgrades, e.g. if the default CreateView code receives changes in the saveModel function definition.
Also, if you want to do some further reading on extending views, there is an SugarCRM dev blog post about this topic: https://developer.sugarcrm.com/2014/05/28/extending-view-javascript-in-sugarcrm-7/
I resolved this by using logic hook (after save), for your information, I am using Sugar 6.5 no matter the version of suitecrm.
Thank you !

IT Hit WebDAV Ajax Browser Custom Columns

I am looking at a trial of the Ajax Browser Control by ItHit. So far it seems to be pretty responsive when it comes to pulling files across http protocol.
What I want to do at this point is have the details view pull custom properties from my excel workbooks. What is the most efficient way to connect my C# code that gets the custom properties to the Ajax control to display the correct values?
The easiest way to create a custom column is to return custom property from a WebDAV server. In the example below the server returns price in PricesNs:RetailPrice property.
On a client side you will define a custom column and specify custom property name and namespace:
{
Id: 'MyColumn1',
CustomPropertyName: 'RetailPrice',
CustomPropertyNamespace: 'PricesNs',
Text: 'Retail Price',
Width: '150px'
}
Another approach is to return an HTML from a Formatter function specified for column. You have a full control over what is being displayed in this case.
You can find more details and an example in this article: http://www.webdavsystem.com/ajaxfilebrowser/programming/grids_customization/
In case your WebDAV server is running on IT Hit WebDAV Server Engine, to return the requested property, you must implement IHierarchyItem.GetProperties method (or its asynchronous counterpart):
public IEnumerable<PropertyValue> GetProperties(IList<PropertyName> names, bool allprop)
{
if (allprop)
{
return getPropertyValues();
}
List<PropertyValue> propVals = new List<PropertyValue>();
foreach(PropertyName propName in names)
{
if( (propName.Namespace == "PricesNs") && (propName.Name == "RetailPrice") )
{
// Depending on the item you will return a different price,
// but here for the sake of simplicity we return one price regerdless of the item
propVals.Add(new PropertyValue(propName, "100"));
}
else
{
...
}
}
return propVals;
}

How can the visibility of a button in a form be changed dynamically using x++ code?

How can I change the visibility of my button control MyButton?
I have a form MyForm where I want to set the visibility property for my MyButton button control.
I used this code in the form's init method:
public void init()
{
MyTable myTable;
;
while select myTable where myTable.UserId == curUserId()
{
if (myTable.FlagField == NoYes::Yes )
{
myButton.visible(true);
}
if (!myTable.FlagField == NoYes::No )
{
myButton.visible(false);
}
}
super();
}
The property AutoDeclaration of MyButton is set to Yes. But when I open the form, I get the following error:
"Failure initializing FormButtonControl object."
I think I have to use the FormButtonControl class, but I no have idea how to do that.
FH-Inway's answer is correct from a code-perspective, but I want to comment that what you're doing is incorrect and won't function properly unless your mineTable only has 1 matching record.
Currently as written, when the form is instantiated, you basically loop over mineTable and toggle the myButton visible and hidden over and over for every record where mineTable.UserId == curUserId() , then the form is displayed and whatever the last record happens to be.
That's the difference between while select [table] where [clause] {[code]} and select [table] where [clause];.
If you only have one record in that table you should change it to:
MineTable mineTable;
super();
select firstonly mineTable where mineTable.UserId == curUserId();
if (mineTable)
{
if (mineTable.FlagField== NoYes::Yes )
{
myButton.visible(true);
}
if(!mineTable.FlagField== NoYes::No )
{
myButton.visible(false);
}
}
else
{
throw error("Record not found or whatever your error should be");
}
The controls of a form are initialized by the super() call in the form's init method. To change the properties of a form control, it has to be initialized first, so you have to place the code that changes the property after the super() call.

How to send and access a parameter/value upon Form Submission to next controller

I am new to Laravel.
I have a controller method which retrieves data from request, creates a model instance
and saves it to database.
It then redirects to controller with a value (user name)
return redirect()->action('SignupController#confirm' , $username);
Route for confirm is :
Route::get('confirm/{user}' , 'SignupController#confirm');
In 'confirm' method i retrieved value from variable and passed it to view
public function confirm($username)
{
return view('auth.confirm')->with('username' , $username);
}
Confirm view present a form to confirm account and upon succesful submission post to route :
Route::post('confirm' , 'SignupController#confirmCode');
In 'confirmCode' i want to access that value which i actully fetched from user input
and passed down the line.
But i am unable to do it , i even tried post route with a wild card
Route::post('confirm/{user}' , 'SignupController#confirmCode');
and tried to access it similarly as before , but it is not passed along when form submits as i get nothing when i
tried to look for it using var_dump($username).
Error is :
Missing argument 1 for App\Http\Controllers\SignupController::confirmCode()
By the way, temporarily i am using hidden field to do the job which is not a good idea obviously.
I know i am missing something. Looking forward for some advice. Thanks in advance.
You can simply use Session::flash or if it's more than one redirect then you can use Session::put.
use Session; // at the top between class and namespace
public function confirm($username)
{
Session::flash('username', $username);
// Session::put('username',$username);
return view('auth.confirm')->with('username' , $username);
}
public function confirmCode() {
dd(Session::get('username'));
}

Zend_Form - How to addValidator after the form has been submitted

I have 2 text fields in my form.
TextFieldA - not required
TextFieldB - not required
After user submitted the form,
How to add validator / setRequired(true) to TextFieldB if the value of TextFielA is not empty?
I see two approaches in addition to #Marcin's idea.
Conditionally call setRequired() on the relevant elements by creating a preValidate() method on the form and calling it in your controller. [Really the same idea as #Marcin, but pushed down into the form itself, keeping the controller a bit leaner.]
Create a custom validator called something like ConditionallyRequired that accepts as an option the fieldname of the "other field". Then attach this validator to each element, configuring it with the name of the "other" element. Then in the validator's isValid($value, $context) method, conditionally test $value if $context['otherfield'] is non-empty.
You could do as follows:
if ($this->getRequest()->isPost()) {
$textFieldA = $yourForm->getElement('TextFieldA');
$textFieldB = $yourForm->getElement('TextFieldB');
if (!empty($_POST['TextFieldA'])) {
$textFieldB->setRequired(true);
}
if (!empty($_POST['TextFieldB'])) {
$textFieldA->setRequired(true);
}
if ($mainForm->isValid($_POST)) {
// process the form
}
}
Basically, you add the validators after the post, but before the form is validated.
Hope this helps.