Programmatically adding new datagridfield row

I'm trying to upgrade from Plone 5.2 to 6 and collective.z3cform.datagridfield 1.5.3 to 3.0.0. I have some code that allows a user to paste text into a single textarea that is parsed and inserted into the grid. The parsing is outside of scope here, I'm just trying to work with DGF functionality. Given a "name" object a jQuery selector "el" I can put its components into separate grid inputs like this in 1.5.3

el.find('.auto-append [id$="iname"]').val(name.initials);
el.find('.auto-append [id$="lname"]').val(name.last_name);
el.find('.auto-append [id$="fname"]').val(name.first_name);
el.find(' td').trigger('change');  // make new row

In 3.0.0 I can insert into a row the same way, but the trigger to create a new row seems to have changed. Based on collective.z3cform.datagridfield/datagridfield.pattern.js at 3bc8f6bbf5fd9a442e13406f597edab37fa6d978 · collective/collective.z3cform.datagridfield · GitHub I would have thought I could do el.find('.auto-append').trigger('focusout') but this does not do anything and I'm not sure what I need to do to generate the next line?

@petschki any hints on how to trigger a new line to be added? I'm stuck

Hi. I would use the pattern code directly:


Make sure, that el is the DOM element and not the jQuery element.

EDIT: if its the jQuery element you can use $"pattern-datagridfield").auto_append_row()

Thanks much! I didn't realize you could call el["pattern-datagridfield"] to access all of those functions, that opens up a new world for me

This is the patternslib API: Patterns/base.js at master · Patternslib/Patterns · GitHub ... every instance of a pattern is saved to its element.