Netzke change form header title - extjs

def preconfigure_record_window(c)
super
c.header = true
c.width = 600
c.draggable = false
c.title = "New Title"
end
In this code I want to change the form title. Whatever I am trying it is displaying the default title Add

You'd need to define it separately for add and edit actions:
component :add_window do |c|
super(c)
c.title = "New title - add"
...
end
component :edit_window do |c|
super(c)
c.title = "New title - edit"
...
end

Related

How handle click event of remove item button in multiselect combobox vaadin 14

Would like to show confirmation dialog when any of the selected items is removed from multi select combo box. We have this token remove button and its click event I would like to know how we can handle its click event in java ?
There's no Java API for the click listener of the items. However, if you want to add a confirmation step for deselection, you can use a workaround with a selection listener, as the selection event knows the previous selection set and the new selection set:
MultiselectComboBox<String> multiselectComboBox = new MultiselectComboBox();
multiselectComboBox.setLabel("Select items");
multiselectComboBox.setItems("Item 1", "Item 2", "Item 3", "Item 4");
multiselectComboBox.addSelectionListener(event -> {
if (!event.isFromClient()) {
return;
}
Set<String> removedSelection = event.getRemovedSelection();
if (removedSelection.isEmpty()) {
return;
}
String itemsAsString = String.join(",", removedSelection);
ConfirmDialog confirmDialog = new ConfirmDialog();
confirmDialog.setHeader("Are you sure you want to remove " + itemsAsString);
confirmDialog.setConfirmButton("Ok", null);
confirmDialog.setCancelButton("Cancel", e -> {
multiselectComboBox.select(event.getOldSelection());
});
confirmDialog.open();
});
This won't preserve the order of the selection, but that might be doable as well with a little bit of effort.

Wrong FieldRowPanel

Is my FieldRowPanel wrong?
padding = FieldRowPanel([
FieldPanel(blocks.ChoiceBlock(
required=False, choices=PADDING_CHOICES, label="Отступ сверху")),
FieldPanel(blocks.ChoiceBlock(
required=False, choices=PADDING_CHOICES, label="Отступ снизу")),
], heading="Отступы")
I am trying to do it in this place:
class ContentBlockThemed(blocks.StructBlock):
theme = blocks.ChoiceBlock(
required=True, choices=BLOCK_THEMES_CHOICES, label="Тема")
padding = FieldRowPanel([
FieldPanel(blocks.ChoiceBlock(
required=False, choices=PADDING_CHOICES, label="Отступ сверху")),
FieldPanel(blocks.ChoiceBlock(
required=False, choices=PADDING_CHOICES, label="Отступ снизу")),
], heading="Отступы")
visible = blocks.BooleanBlock(required=False, label="Видимый", default=True, help_text="По умолчанию - True")
block_content = ContentBlock()
class Meta:
icon = 'user'
form_classname = 'content-block struct-block pages-content-block'
template = 'wtblocks/content_block.html'
Nothing is displayed in the admin, although there is no error
This is not valid code.
blocks.ChoiceBlock is only valid inside a StreamField definition
FieldRowPanel and FieldPanel are not valid inside a StreamField definition, only inside the 'panels' definition of a model
FieldPanel should be passed a field name as a string, not a block object
To control the layout of the edit form for a StructBlock (i.e. the equivalent of how you'd use FieldRowPanel in a panel definition), you need to define that layout as an HTML template and set that template as form_template in the block's Meta section.

Dropdown list not showing default item

I am using the semantic-ui-react dropdown list, which I have working just fine. The problem is, on my form I am pulling data from a database using the Mobx store. I have a array setup for the options in the dropdown list. when the form loads from the store the text field for the dropdown list is blank, if I click on the dropdown I can see that the selected option is highlight (bold). How do I get the text field to show the default options. I have included some code below if anyone can look at it and give me an idea of what I need to do.
Thanks for all your help.
Here is the code for the dropdown list:
<div className="col-sm-3">
<div className="bg-primary text-white text-center">
Driver
</div>
<div>
<Dropdown
selection
fluid
id="driver"
name="driver"
ref="driver"
onChange={this.handleChange}
value={this.props.EquipmentStore.truck_detail.driver}
options={this.props.EquipmentStore.driver_list}/>
</div>
</div>
Here is how I am building the driver_list, I am basically getting a list of users from the database and create an array with value and text fields
let newUserItem = {
value: getUser.id,
text: getUser.first_name + " " + getUser.last_name
};
this.driver_list.push(newUserItem)
The value in the truck_detail.driver is a numberic value that the same value in the value field in the driver_list value field...that is all working fine, I can not get the text value to show in the text field for the dropdown list by default.
Here is the code that I use to build the options list:
async loadDriverList() {
let endpoint = '/api/users/profile/?owner=True';
this.driver_list.length = 0;
let lookupOptions = {
method: "GET",
headers: {
'Content-Type': 'application/json'
}
};
try {
const response = await fetch(endpoint, lookupOptions);
const profile_list = await response.json();
const userItem = {value:0, text:'Select Driver'};
this.driver_list.push(userItem);
let array_length = profile_list.length;
for (let i = 0; i < array_length; i++) {
let ownerId = profile_list[i].user;
let endpoint = '/api/users/users/' + ownerId + '/';
let userList = await fetch(endpoint, lookupOptions);
let getUser = await userList.json();
let newUserItem = {
value: getUser.id,
text: getUser.first_name + " " + getUser.last_name
};
this.driver_list.push(newUserItem)
}
} catch(e) {
console.log(e)
}
}
After a lot of conversation with Predrag Beocanin I have solved this issue. What it boils down to is my form (with the Dropdown) was getting render before the options list was fully populated. In my application I have a form that shows a list of items, once you click on the item it will render a detailed form of that listed item. Originally I wall trying to populate my options list once you click on the item you wanted to view the details on. Because the options list is basically a static list, I am now populating that list when you are view the first form. Now when you click on the item to view the Dropdown options are fully populated and working just as I had expected.
Thanks for your help Predrag.

Cannot make a model #property def-as-field work with wagtail 2.0

I'm using Wagtail 2.0 with a custom Block that has the following code:
class LinkButtonBlock(blocks.StructBlock):
label = blocks.CharBlock()
URL = blocks.CharBlock()
styling = blocks.ChoiceBlock(
choices=[
('btn-primary', 'Primary button'),
('btn-secondary', 'Secondary button'),
('btn-success', 'Success button'),
('btn-info', 'Info button'),
('btn-warning', 'Warning button'),
('btn-error', 'Error button'),
],
default='btn-info',
)
outline = blocks.BooleanBlock(
default=False
)
#property
def css(self):
btn_class = self.styling
if self.outline is True:
btn_class = btn_class.replace('btn-', 'btn-outline-')
return btn_class
class Meta:
icon = 'link'
template = 'testapp/blocks/link_button_block.html'
If I then try to access this css "property" in my template, nothing seems to happen. Putting a print(self) as first line inside the css def also shows nothing on the console suggesting the function never even gets called.
Using the following template:
{% load wagtailcore_tags %}
<a class="btn {{ block.value.css }}" href="{{ block.value.URL }}">{{ block.value.label }}</a>
Simply yields:
<a class="btn " href="actual.url.from.instance">actual.label.from.instance</a>
Also, block.value.styling and block.value.outline on their own work just fine, so... what am I doing wrong here?
The thing that's tripping you up is that the value objects you get when iterating over a StreamField are not instances of StructBlock. Block objects such as StructBlock and CharBlock act as converters between different data representations; they don't hold on to the data themselves. In this respect, they work a lot like Django's form field objects; for example, Django's forms.CharField and Wagtail's CharBlock both define how to render a string as a form field, and how to retrieve a string from a form submission.
Note that CharBlock works with string objects - not instances of CharBlock. Likewise, the values returned from StructBlock are not instances of StructBlock - they are a dict-like object of type StructValue, and this is what you need to subclass to implement your css property. There's an example of doing this in the docs: http://docs.wagtail.io/en/v2.0/topics/streamfield.html#custom-value-class-for-structblock. Applied to your code, this would become:
class LinkButtonValue(blocks.StructValue):
#property
def css(self):
# Note that StructValue is a dict-like object, so `styling` and `outline`
# need to be accessed as dictionary keys
btn_class = self['styling']
if self['outline'] is True:
btn_class = btn_class.replace('btn-', 'btn-outline-')
return btn_class
class LinkButtonBlock(blocks.StructBlock):
label = blocks.CharBlock()
URL = blocks.CharBlock()
styling = blocks.ChoiceBlock(choices=[...])
outline = blocks.BooleanBlock(default=False)
class Meta:
icon = 'link'
template = 'testapp/blocks/link_button_block.html'
value_class = LinkButtonValue

Codenameone validator not highlighting required fields

I have a simple form that performs validation of each field. For some reason, I think related to the CodenameOne theme, I do not get a red outline or background for fields failing validation, and I do not see the error messages. The form will gray out the "Submit" button until all validations pass, so this part is working. I just can't see the errors on the screen. I have included my form code below. Is this happening because the default theme I am using does not have the required UUIDs to display the error styles?
Is there a way to debug when styles are being applied but are not available in the theme?
Form registrationForm = new Form("My Registration");
BorderLayout bl = new BorderLayout();
bl.setCenterBehavior(BorderLayout.CENTER_BEHAVIOR_CENTER);
registrationForm.setLayout(bl);
registrationForm.setFormBottomPaddingEditingMode(true);
ComponentGroup cg = new ComponentGroup();
final TextField nicknameField = new TextField("", "Screen name (publicly viewable)", 25, TextArea.ANY);
cg.addComponent(nicknameField);
final TextField emailField = new TextField("", "Email address", 40, TextArea.EMAILADDR);
cg.addComponent(emailField);
final TextField passwordField = new TextField("", "Password", 40, TextArea.PASSWORD);
cg.addComponent(passwordField);
final TextField passwordConfirmField = new TextField("", "Type your password again", 40, TextArea.PASSWORD);
cg.addComponent(passwordConfirmField);
final TextField sloganField = new TextField("", "Slogan (publicly viewable), ex: Go Hokies!", 30, TextArea.ANY);
cg.addComponent(sloganField);
Button submit = new Button("Submit");
Validator v = new Validator();
v.addConstraint(nicknameField, new LengthConstraint(3));
v.addConstraint(emailField, RegexConstraint.validEmail("You must enter a valid email address to receive confirmation"));
v.addConstraint(passwordField, new LengthConstraint(8));
v.addConstraint(passwordConfirmField, new LengthConstraint(8));
v.addSubmitButtons(submit);
submit.addActionListener((e) -> {
String password = passwordField.getText();
String passwordConfirm = passwordConfirmField.getText();
if (!password.equals(passwordConfirm)) {
Dialog.show("Password error", "The password and password confirmation did not match. Please retype them.", "OK", null);
} else {
showConfirmation();
}
});
cg.addComponent(submit);
registrationForm.addComponent(BorderLayout.CENTER, cg);
registrationForm.show();
The error mode sets the UIID to existing UIID with the word "Invalid" appended to it. So a TextField will become TextFieldInvalid.
In the simulator open the Component Inspector tool and traverse the components to see the UIID's that they have. This will allow you to customize the right UIID's in selected/unselected states.
To enable error message display use setShowErrorMessageForFocusedComponent(true).

Resources