Add field doesn't work properly when form already shown

Add field doesn't work properly when form already shown

datacollectdatacollect Posts: 6Questions: 4Answers: 0

Hi,

when i add a fields while the form is displayed, iam not able to get them displayed until i close and reopen the form by clicking on 'New' button. My goal is, when i change the value of the select field 'product', a request is sent to the server with additional fields, which i want to display directly on the form.

I hope someone can help.

                var additional_fields = [];
                    
                RMAArrivalObjectsEditor.dependent( 'product', function ( val, data, callback ) {
                    if (val == "") return false; // on form init this event fires, why?
                    
                    $.ajax( {
                        method: "POST",
                        data: { product: data.values.product },
                        url: '/rma/arrival/update/',
                        success: function ( json ) {
                            
                            console.log("inner ajax");
                        
                                                // Add additional fields
                            $.each(json.fields, function (field_name, value) {
                                
                                RMAArrivalObjectsEditor.add({
                                    label: value.label,
                                    name: field_name
                                    
                                }).hide(field_name);
                                
                                additional_fields.push(field_name);
                                
                            })
                            
//                          callback({
//                              show: additional_fields,
//                              hide: "serial" // this works
                                
//                          })
                            RMAArrivalObjectsEditor.hide(additional_fields);
                            RMAArrivalObjectsEditor.show(additional_fields, true); // nothing happens
                            
                            //RMAArrivalObjectsEditor.display(true)

                        }
                    } );
                    
                    console.log("outer ajax");
                } );

Answers

  • allanallan Posts: 61,776Questions: 1Answers: 10,112 Site admin

    Hi,

    This unfortunately appears to be a bug in 1.4. A workaround is to use:

    RMAArrivalObjectsEditor.order( RMAArrivalObjectsEditor.order() )

    That will cause the display to redraw with the new rows. Really add() should be immediately redrawing the display, which I will ensure is done in 1.5.

    Thanks for letting me know about this.

    Allan

This discussion has been closed.