The use of ReferenceArrayInput - admin-on-rest

I've an issue with ReferenceArrayInput that I try to use for a group membership representation.
Here the code related to a group editing UI
export const UserGroupEdit = (props) => (
<Edit title={<UserGroupTitle />} {...props}>
<SimpleForm>
<TextInput label="Common Name" source="commonName" />
<TextInput label="E-mail" source="email" type="email" />
<TextInput label="Shortname (UNIX purpose)" source="shortname" />
<ReferenceArrayInput label="Members" source="members" reference="users">
<SelectArrayInput optionText="fullName" />
</ReferenceArrayInput>
<DisabledInput label="Record UUID" source="id" />
<DisabledInput label="Record ID" source="numericID" />
</SimpleForm>
</Edit>
);
I've two issue.
First, if the related property in the represented object is empty, the UI does not display the input field. It show the title of the field, a whitespace with no input possible and the next one. When I pass the mouse over the whitespace, I get the same icon attached to the mouse as a DisabledInput, the forbidden sign.
Second, if there is already one value, I can add new one, I've the text input available and the autocompletion is working well. However, once I select one value to add, it immediately disappear. It does not stay in memory until the save or cancel action.
And if in the second case, I remove existing values, they get properly removed and once I remove everything I'm back to the first issue.
Is there something I'm doing wrong?

About your first issue, you can try to add a allowEmpty prop to your ReferenceArrayInput :
<ReferenceArrayInput label="Members" source="members" reference="users" allowEmpty>

It's a bug indeed. This issue has been fixed on master which will be released soon as version 1.4.0.

Related

Get name from textChange event in nativescript-vue

have this code:
<TextField
v-model="lastname"
#textChange="ontextChange"
name="lastname"
/>
and i want get name from event:
ontextChange(args){
console.log(args.name)
}
but i thing it's wrong.
You are accessing the wrong attribute in the arguments. It's of type EventData, you must be looking for args.eventName.
Update:
If you want to access the actual TextField which triggered the event, args.object should work.

ReferenceInput and SelectInput first option

I have a filter that has a SelectInput inside a ReferenceInput and it has only one option.
I really need that first option to be selected.
<ReferenceInput source="BranchID" reference="branches" allowEmpty alwaysOn perPage={1000}>
<SelectInput optionText={choice => `${choice.number +" "+ choice.address}`} />
</ReferenceInput>
You can achieve that using default values on your form: https://marmelab.com/admin-on-rest/CreateEdit.html#default-values

How to access record's internals in Show/Edit/Create

Similar to admin-on-rest: Access row's column data within a Datagrid component although I think it doesn't apply to my cases:
export const PlantShow = (props) => {
return (<Show {...props}>
<TabbedShowLayout>
<Tab label="Analytics">
{ record.oneId && <MetricsCharts {...props} manufacturer="one" /> }
{ record.otherId && <MetricsCharts {...props} manufacturer="other" /> }
{ record.anotherId && <MetricsCharts {...props} manufacturer="another" /> }
</Tab>
</TabbedShowLayout>
</Show>)
}
There should be a way to access current record's internals so I can introduce conditional logic .. I didn't find anything useful in props.. I even tried to inject {record} in PlantShow function but that didn't work either. Also DependentInput definitely doesn't help here
Thanks!
You'll have to use an intermediate component as a child of Show. It will receive the record prop.
See https://codesandbox.io/s/wyln51r907 (in posts.js, around the PostShow component.

Passing context to domain in Odoo 9

In model
batch_id = fields.Many2one('ae.batch', 'Batch')
subject_ids = fields.Many2many('ae.subject', string="Subjects")
topic_ids = fields.Many2many('ae.topic', string="Topics")
subtopic_ids = fields.Many2many('ae.subtopic', string="Subtopics")
The goal is to pass context in order to filter(domain), picking a Batch filters Subjects, choose Subjects, could be one or more, to filter Topics, and filter Subtopics.
Batch (Many2one) to Subjects (Many2many)
Subjects (Many2many) to Topics (Many2many)
Topics (Many2many) to Subjects(Many2many)
Check view:
<group col="4" name="plan_detail" String='Choose t'>
<field name="batch_id"
context="{'batch_id':batch_id}"/>
<field name="subject_ids"
domain="[('batch_id', '=', batch_id)]"
context="{'subject_ids': subject_ids}"/>
<field name="topic_ids"
domain="[('subject_id', 'in', 'subject_ids')]"
context="{'topic_ids': topic_ids}" />
<field name="subtopic_ids" widget="many2many_checkboxes"
domain="[('topic_id', 'in', topic_ids)]" />
What is working, picking the Batch filters correctly all Subjects.
Stucked between Subjects and Topics, I think is a context or domain problem, I've tested changing the domain manually like so:
<field name="topic_ids"
domain="[('subject_id', 'in', '[1, 2]')]"
context="{'topic_ids': topic_ids}" />
And successfully gets Topic list. I guess I am wrong passing context or getting domain. Help.
Thanks in advance.
In your code, in the domain, the field that you mentioned subject_ids are in between quotes. Since its representing a field remove the quotes and do.
Try this
<field name="topic_ids" domain="[('subject_id', 'in', subject_ids)]"
context="{'topic_ids': topic_ids}" />

Adding a row in a picker on alloy

well I have this code in a view
<Picker id="picker1" selectionIndicator="true" class="picker">
<!-- Picker shorthand notation -->
<Column id="column1" class="column">
<Row title="option1" />
<Row title="option2" />
<Row title="option3" />
</Column>
</Picker>
and I have been trying to change the rows on the controller, since I receive different options from the server, lets say for example:
( option4, option5, option6 )
I tried adding a row to the picker like this:
$.column1.addRow(Ti.UI.createPickerRow({title:'option4'}));
and had no success too, looking through the forums on appcelerator it wasn't possible before titanium SDK 5.1.0 GA to dynamically update the picker, but on another topic I've read that it is possible to do it but you have to reload the picker, so I tried it, but no success
var picker = $.picker1;
var column = $.column1;
column.addRow(Ti.UI.createPickerRow({title:'option4'}));
picker.reloadColumn(column);
how should be the right way to do it? adding a row and removing others, that is my question.
I am testing on an iphone(9+) and android(5+), using the Titanium SDK 5.1.2GA.
Solved, it was just a mistype, sorry, but you need to reload the column, or else it will not work.
var picker = $.picker1;
var column = $.column1;
column.addRow(Ti.UI.createPickerRow({title:'option4'}));
picker.reloadColumn(column);

Resources