redux-form immutable submit all fields - redux-form

I am using redux-form immutable, I am trying to do simple todo list, I am using FieldArray for todo items,
When form is submitted, I do not get the value of index since it is read only for user and I am rendering using div. how to get the value of index during submission of the form. How should MyCustom component look like.
<TableRow selectable={false} key={index}>
<TableRowColumn style={styles.item}>
<Field name={`${todo}.index`} component={MyCustom} val={index + 1} />
</TableRowColumn>
<TableRowColumn style={styles.done}>
<Field name={`${todo}.done`} component={CheckBox} label=""/>
</TableRowColumn>
<TableRowColumn style={styles.description}>
<Field name={`${todo}.description`} component={Text}/>
</TableRowColumn>
<TableRowColumn style={styles.duration}>
<Field name={`${todo}.duration`} component={Duration} type="number" normalize={integer}/>
</TableRowColumn>
<TableRowColumn style={styles.delete}>
{/* <button type="button" title="X" onClick={() => fields.remove(index)}>X</button> */}
<IconButton onClick={() => fields.remove(index)}>
<DeleteIcon/>
</IconButton>
</TableRowColumn>
</TableRow>
MyCustom
<div>
<span>{val}</span>
</div>

index is not a field here, it's just a value. So pass it as a prop.
<MyCustom val={index + 1} />

Related

odoo xml - hide two buttons with same attribute - on condition

I've added a new boolean field(with default False) to the sale_order and added a button to set it as True in the quotation form.
<button name="action_confirm" position="before">
<field name="boolean_field" invisible="1"/>
<button name="set_boolean_field" string="Boolean Field" type="object"
attrs="{'invisible': ['|',('boolean_field', '=', True), ('state','in',('sale','confirm'))]}"/>
</button>
Now, I need to hide the "Confirm Sale" button, when the above boolean field is False, in the quotation form.
There are two such buttons in the form header.
<button name="action_confirm" states="sent" string="Confirm Sale" class="btn-primary o_sale_confirm" type="object"/>
<button name="action_confirm" states="draft" string="Confirm Sale" class="o_sale_confirm" type="object"/>
How do I hide the above two buttons when based on the value of boolean_field?
Thanks.
I can't test it but I think it should be something like that.
It needs the boolean_field first.
It replaces first and second buttons attrs field. If the original buttons already have something in the attrs field then it should be added to here aswell.
<xpath expr="//button[#name='action_confirm'][1]" position="attributes">
<attribute name="attrs">{'invisible': [('boolean_field', '=', False)]}</attribute>
</xpath>
<xpath expr="//button[#name='action_confirm'][2]" position="attributes">
<attribute name="attrs">{'invisible': [('boolean_field', '=', False)]}</attribute>
</xpath>

Radzen DataGrid Multiple Selection only filtered Items

I have a Razor Component (.net 6) where I make use of the Radzen DataGrid Multiple Selection.
<RadzenDataGrid
#ref="contactsGrid" Data="#contacts" AllowColumnResize="true" EditMode="DataGridEditMode.Single"
RowUpdate="#OnUpdateRow" RowCreate="#OnCreateRow"
AllowSorting="true" AllowFiltering="true" FilterCaseSensitivity="FilterCaseSensitivity.CaseInsensitive"
TItem="ContactModel" AllowRowSelectOnRowClick="false" SelectionMode="DataGridSelectionMode.Multiple" #bind-Value=#selectedContacts>
<Columns>
<RadzenDataGridColumn TItem="ContactModel" Width="40px" Sortable="false" Filterable="false">
<HeaderTemplate>
<RadzenCheckBox TriState="false" TValue="bool" Value="#(contacts.Any(i => selectedContacts != null && selectedContacts.Contains(i)))" Change="#(args => selectedContacts = args ? contacts.ToList() : null)" />
</HeaderTemplate>
<Template Context="contacts">
<RadzenCheckBox TriState="false" Value="#(selectedContacts != null && selectedContacts.Contains(contacts))" TValue="bool" Change=#(args => { contactsGrid.SelectRow(contacts); }) />
</Template>
</RadzenDataGridColumn>
<!-- FirstName -->
<RadzenDataGridColumn TItem="ContactModel" Property="FirstName" Title="FirstName">
<EditTemplate Context="contact">
<RadzenTextBox #bind-Value="contact.FirstName" Style="width:100%; display: block" Name="FirstName" />
<RadzenRequiredValidator Text="FirstName is required" Component="FirstName" Popup="true" />
</EditTemplate>
</RadzenDataGridColumn>
<!-- LastName -->
<RadzenDataGridColumn TItem="ContactModel" Property="LastName" Title="LastName">
<EditTemplate Context="contact">
<RadzenTextBox #bind-Value="contact.LastName" Style="width:100%; display: block" Name="LastName" />
<RadzenRequiredValidator Text="LastName is required" Component="LastName" Popup="true" />
</EditTemplate>
</RadzenDataGridColumn>
</Columns>
</RadzenDataGrid>
In the HeaderTemplate you can directly select or deselect all items.
Is it possible to change the function so that only all items are selected that match the filter? i.e. which items are currently displayed when I search for certain items using the filter option?
you can use contactsGrid.View to get visible rows. try to use contactsGrid.View instead of selectedContacts.

Calling invoice from wizard

class InvoiceWizard(models.TransientModel):
_name = "pos.order.invoice.wizard"
date_order = fields.Datetime(string='Date Order', readonly=True)
partner_id = fields.Many2one('res.partner', string='Partner')
#api.multi
def to_invoice(self):
pos_order = self.env['pos.order'].search([('id','=',self._context.get('active_id'))])
pos_order.create_invoice()
<record id="pos_order_invoice_done" model="ir.ui.view">
<field name="name">pos.order.wizard.invoice</field>
<field name="model">pos.order.invoice.wizard</field>
<field name="arch" type="xml">
<form string="To Invoice">
<group>
<field name="partner_id"/>
<field name="date_order"/>
</group>
<footer>
<button name="to_invoice"
string="Finished" type="object"
class="btn-primary"/>
<button string="Cancel"
class="btn-default"
special="cancel" />
</footer>
</form>
</field>
</record>
My goal is to create invoice from pos order with this 2 fields that manuale i will select in wizard. what do i'm missing here? i need to transfer data from those fields to create_invoice() method.
partner_id is required in invoice object, so you must fill the fields in create method like:
#api.multi
def to_invoice(self):
invoice_obj =self.env['account.invoice']
values = {'partner_id' : self.partner_id,
'date_invoice' : self.date_order
}
invoice_obj.create(values)
note : make sure all fields required is filled.

Odoo 8 src variable for iframe in ir.ui.view

Model
class ItemStocks(models.Model):
_name = 'item.stocks'
item_url = fields.Char('View Item')
ItemStocks()
View
<record id="view_item_stocks_form" model="ir.ui.view">
<field name="name">item.stocks.form</field>
<field name="model">item.stocks</field>
<field name="arch" type="xml">
<form string="Item Stocks">
...
<page string="Live Site">
<form string="Embedded Webpage" version="7.0" edit="false">
<iframe marginheight="0" marginwidth="0" frameborder="0"
src="{Variable for this.item_url}" width="100%" height="1000"/>
</form>
</page>
...
</form>
</field>
</record>
How can I replace {Variable for this.item_url} with a valid expression for the field in model? Is there a better way to do like this? What would you prefer to solve the requirement of showing dynamically an embedded webpage?
Context: Odoo 8, New Api, ir.ui.view
**`Image Url wise Set Dynamic Iframe In Odoo`**
# v11 odoo community
you need to create fields like this :
image_url = fields.Char('Image Url')
img_attach = fields.Html('Image Html')
# set image_url in iframe
#api.onchange('image_url')
def onchange_image_url(self):
if self.image_url:
self.img_attach = '<img id="img" src="%s"/>' % self.image_url
# set image_url in form view
<field name="image_url" />
# after added script
<script>
if(document.getElementById("img")){
var value= document.getElementById("img").src;
document.getElementById("custom_src").src=value;
}
</script>
# also set iframe in form view
<iframe id="custom_src" src="" width="200" height="200" />
#output
show the image : https://i.stack.imgur.com/0x7et.png

How do I unhide a CFDIV that has dynamic content with AJAX binding itself?

I have the following CFSELECT tags that are used to populate a text input:
<cfselect id="this" name="this" bind="cfc:Data.getThis()" bindonload="true" />
<cfselect id="that" name="that" bind="cfc:Data.getThat({p1})" />
<cfselect id="theOther" name="theOther" bind="cfc:Data.getTheOther({p1}, {p2})" />
The text input is the only value that needs to be submitted in a form:
<cfform name="addItem" method="post" action="somepage.cfm">
<cfinput
type="text"
id="item"
name="item"
bind="cfc:Data.getResult({this}, {that}, {theOther})" /><br />
<cfinput
type="submit"
name="addButton"
value="Add Item" />
</cfform>
I want the form and it's contents to be visible only when all three selections have been made, and there is a value for the text input. What is the best way to do this? I'm assuming some use of CFDIV is the best way, but I'm not sure how to load the dynamic content (the CFINPUTs) this way.
<cfselect id="this" name="this" bind="cfc:Data.getThis()" bindonload="true" onChange="toggleForm();" />
<cfselect id="that" name="that" bind="cfc:Data.getThat({p1})" onChange="toggleForm();" />
<cfselect id="theOther" name="theOther" bind="cfc:Data.getTheOther({p1}, {p2})" onChange="toggleForm();" />
<div id="theForm" style="display:none">
<cfform name="addItem" method="post" action="somepage.cfm">
<cfinput
type="text"
id="item"
name="item"
bind="cfc:Data.getResult({this}, {that}, {theOther})" /><br />
<cfinput
type="submit"
name="addButton"
value="Add Item" />
</cfform>
</div>
<script type="text/javascript">
function toggleForm(){
var a = document.getElementById("this").selectedIndex;
var b = document.getElementById("that").selectedIndex;
var c = document.getElementById("theOther").selectedIndex;
if (a > -1 && b > -1 && c > -1){
document.getElementById("theForm").style.display = "";
}
}
</script>
Personally I would simplify that JS a bit by using jQuery, but I don't know if you're already using jQuery on your site, and I don't want to be another "use jquery" empty answer; so this should work without jQuery, should you want/need to go without it. (But jQuery is awesome!)

Resources