I have a View with 2 textbox and a button that call an action on a ViewModel to show another View; that what will show in it depends on values of 2 texbox.
For that reason before to call my ViewModel i want to check textbox values and if its are empty show a Dialog. Now to call my ViewModel i have add a binding like this:
this.AddBindings(new Dictionary<object, string>()
{
{ btnSearch, "TouchUpInside GoParameterizedCommand" },
});
as Swiss Binding. Now if i want to use same event to check if my textbox are valorized and don't call GoParameterizedCommand, how could i do?
You could bind all your controls to ViewModel properties like:
this.AddBindings(new Dictionary<object, string>()
{
{ btnSearch, "TouchUpInside GoCommand" },
{ text1, "Text MyText" },
{ switch1, "On MyOption" },
// ...
};
Then inside the GoCommand handler you could put whatever logic you need:
public ICommand GoCommand
{
get
{
return new MvxCommand(() => {
if (MyOption)
{
ShowViewModel<OptionViewModel>();
}
else
{
ShowViewModel<DetailViewModel>(new { text = MyText });
}
});
}
}
For showing a dialog - eg an error dialog - then this might be best done using a messenger - sending an error message from the viewmodel. There are a few questions on here about error handling - eg http://slodge.blogspot.co.uk/2012/05/one-pattern-for-error-handling-in.html - plenty of other options are available for giving the user a hint about what to do - eg you could bind the background colour of the text field to an IsMyTextValid property.
Related
I’m a beginner, I can’t pass this level, please help.
I have a lot of forms with TextField (cust_no, cust_name), each with a button on the right,
press the button
A dialog can be display custom record, after selecting the required customer,
Write the selected cust_no, cust_name back to the Text_Field of Form.
I hope to write dialog as a public class, so that many class Forms can use this function, and can also smoothly write cust_no and cust_name back to their respective Form TextField.
In addition to backfilling cust_no,cust_name TextField for some Forms, some also need to query the consumption amount and write back the specified cust_amt TextField.
My trouble is that form button.addClickListener open a dialog,
Dialog’s Button_OK.addClickListener cannot know how I want to write back Form TextField and some have special query mechanisms, how to customize
Without seeing exactly how your code is structured, I can only give a quite generic answer. What you need is typically that something associated with the button for opening the dialog can know what to do with the result from the dialog, and it can also configure the dialog's OK button to carry out that action.
public class HelloWorldView extends VerticalLayout {
public HelloWorldView() {
TextField customerNumberField = new TextField("Customer number");
TextField customerNameField = new TextField("Customer name");
Button nameDialogButton = new Button("Open dialog", dialogOpenClick -> {
showDialog(customer -> {
customerNumberField.setValue(customer.getNumber());
customerNameField.setValue(customer.getName());
});
});
add(customerNumberField, customerNameField, nameDialogButton);
}
private void showDialog(Consumer<Customer> selectionAction) {
Select<Customer> customerSelect = new Select<>(new Customer("1", "Customer 1"),
new Customer("2", "Customer 2"));
customerSelect.setTextRenderer(customer -> customer.getName());
Dialog dialog = new Dialog();
dialog.add(customerSelect);
dialog.add(new Button("Select customer", click -> {
Customer selectedCustomer = customerSelect.getValue();
if (selectedCustomer != null) {
selectionAction.accept(selectedCustomer);
}
dialog.close();
}));
dialog.open();
}
}
I am trying to add the Service Order Line Ref field (SODetID) to the Appointment Entry screen (FS300200). I am able to see the field in the grid and the form view. But I can't seem to make it show in the mobile app on my Android. I tried 2 different MSDL's, a simple and a more complex one, and neither seem to work. However, both add the field in the preview like I would expect. Any help would be greatly appreciated, as always! Here is the MSDL I tried:
Simple:
update screen FS300200 {
update container "Details" {
add field "SODetID" {
placeBefore field "InventoryID"
}
}
}
More Complex:
update screen FS300200 {
update container "Details" {
add field "SODetID" {
placeBefore field "InventoryID"
displayName = "SO Line Ref"
forceIsVisible = True
selectorDisplayFormat = Key
pickerType = Searchable
selector {
fieldsToShow = 5
add field "SODetID" {
listDisplayFormat = CaptionValue
}
add field "InventoryID" {
listDisplayFormat = CaptionValue
}
add field "TranDesc" {
listDisplayFormat = CaptionValue
}
add field "LineType" {
listDisplayFormat = CaptionValue
}
add field "Status" {
listDisplayFormat = CaptionValue
}
}
}
}
}
One quick note, I am using the CacheAttached event to display an extra column in the lookup as well as to make sure Visible = true.
[PXMergeAttributes(Method = MergeMethod.Merge)]
[PXCustomizeSelectorColumns(new[] {
typeof(FSSODet.lineRef),
typeof(FSSODet.inventoryID),
typeof(FSSODet.tranDesc),
typeof(FSSODet.lineType),
typeof(FSSODet.status),
typeof(FSSODet.lastModifiedDateTime),
})]
[PXUIField(DisplayName = "Service Order Line Ref.", Visible = true)]
protected void FSAppointmentDet_SODetID_CacheAttached(PXCache cache)
{
}
I was using the DAC name for SODetId instead of the Web Service name of ServiceOrderLineRef. At least it was an easy fix!
when you hit edit in orchard for a menu it takes you to the widget. I am trying to figure out how to make the edit link go to the specific navigation that the menu widget holds.
You can alter default Display/Edit/Remove links for any content item by using OnGetContentItemMetadata method inside a content handler.
In your specific example, making edit link for a widget to point to the underlying menu editor would look like:
public class MyHandler : ContentHandler
{
public MyHandler()
{
OnGetContentItemMetadata<MenuWidgetPart>((ctx, part) =>
{
ctx.Metadata.EditorRouteValues = new RouteValueDictionary
{
{ "Area", "Navigation" },
{ "Controller", "Admin" },
{ "Action", "Index" },
{ "menuId", part.MenuContentItemId }
};
});
}
}
I want to use setOnCloseRequest after my stage has been started but i get almost a NullPointerException although i set the right controller.
I click on a menuitem to open the stage and after the menu is open i want to use the close button. I think the method tries to access until the controller has been initialized.Actually i want to say: Please controller you are just allowed to do something after you are initialized.
THis is my code of the controller.
if (KundenDatenController.getInstance() != null) {
((Stage) (KundenDatenController.getInstance().kundenControllerPane.
getScene().getWindow())).setOnCloseRequest(new EventHandler<WindowEvent>() {
#Override
public void handle(WindowEvent t) {
t.consume();
if (generalControler.controlEmptyTextField(pflichtfelder)) {
((Stage) (kundenControllerPane.getScene().getWindow())).close();
} else if (!generalControler.controlEmptyTextField(pflichtfelder)) {
FXOptionPane.showConfirmDialog((Stage) (kundenControllerPane.getScene().getWindow()),
"Sollen die Eingaben wirklich verworfen werden?",
"Programm schliessen");
if (status.equals("Laden")) {
KundenUebersichtController.getInstance().setStatus("Aufnehmen");
}
}
}
});
I Have created a dialog in a class, the dialog method is as below
static void dialog(Args _args)
{
Dialog dialog;
DialogField dialogFieldCurrentState;
DialogField dialogFieldNewState;
CustInvoiceTable custInvoiceTable;
;
custInvoiceTable = _args.record();
dialog = new Dialog("Change State");
dialogFieldCurrentState = dialog.addField(TypeID(State_LT),"Current State: ");
dialogFieldCurrentState.value(custInvoiceTable.State);
dialogFieldCurrentState.enabled(false);
dialogFieldNewState = dialog.addField(TypeID(State_LT),"New State: ");
if (dialog.run())
{
custInvoiceTable.State = dialogFieldNewState.value();
}
}
in my dialog there are two fileds Current State and New State .Now when i select the New State the list of all
states is displayed(irrespective of country) which i dont want. Only the states respective of country has to be shown
in the lookup
. I need to make use of a filter something like e.g. while select while select AddressState
where addressState.CountryRegionId == custInvoiceTable.CountryRegionId; so that only states which
are related to a country is shown.
State_LT here is an string EDT (where i put in the relation of State_LT) State_LT == AddressState.StateId
IN AdressState there is a method lookupStateId(), How to call it from a dialog(code above)
?
I am answering to your last question: "IN AdressState THERE IS A METHOD lookupStateId(), HOW TO CALL IT FROM A DIALOG(code above) ?" - by the way writing in capital letters doesn't help people understand your point better.
It is not clear why your dialog is a static method, anyway you'd need the following.
Let's say your ClassDeclaration looks something like this:
class TestClass1 extends RunBase
{
Dialog dialog;
DialogField dialogFieldCurrentState;
DialogField dialogFieldNewState;
// etcetera
}
Your dialog is something like this:
public Object dialog()
{
;
dialog = super();
dialogFieldCurrentState = dialog.addField(TypeID(AddressStateId),"Current State: ");
dialogFieldCurrentState.enabled(false);
dialogFieldNewState = dialog.addField(TypeID(AddressStateId),"New State: ");
dialogFieldNewState.lookupButton(FormLookupButton::Always); // If needed
return dialog;
}
To implement a lookup the way you want it you need to do two things. First, open the dialog, right click on the New State, click Setup, and check the control's System Name. If for example it is Fld2_1 then you need to create the following method:
void fld2_1_lookup()
{
Object control = dialog.formRun().controlCallingMethod();
;
AddressState::lookupStateId(control, dialogFieldNewState.value());
}
Second, it is necessary to override the following method:
public void dialogPostRun(DialogRunbase _dialog)
{
super(_dialog);
_dialog.dialogForm().formRun().controlMethodOverload(true);
_dialog.dialogForm().formRun().controlMethodOverloadObject(this);
}
That should do the trick. I haven't done it for a while but I don't think I forgot something.
Example of looking up customer in dialog:
For example, to have a customer choice dropdown in the dialog,
In report class declaration method --->
DialogField CustomerDlg;
CustAccount customer;
In the reports dialog method: ----->
dialog.addGroup("Customer");
CustomerDlg = dialog.addField(typeid(CustAccount));
CustomerDlg.value(customer);
In the getFromDialog method: ---->
...
customer = CustomerDlg.value();