wagtailstreamforms icon indicating copy to clipboard operation
wagtailstreamforms copied to clipboard

Additional Extension Points in FormBuilder and FormFieldStreamBlock

Open rgs258 opened this issue 5 years ago • 12 comments

This change just refactors the code a bit by creating new methods to override when subclassing FormBuilder or FormFieldStreamBlock for customization:

  • In FormBuilder, created: create_field_class and create_field_name
  • In FormFieldStreamBlock, created: instantiate_block
  • In BaseField, created: get_local_blocks
  • In BaseField, created: get_form_block_class
  • In BaseField, created: get_form_block_kwargs

Please let me know if there's anything else I can do to help this get merged. If you need me to write tests, if you can you please let me know what the signature of each test should be, I will fill in the blanks.

Thanks!

rgs258 avatar Nov 18 '20 21:11 rgs258

Merged #170

rgs258 avatar Mar 18 '21 18:03 rgs258

Codecov Report

All modified and coverable lines are covered by tests :white_check_mark:

Comparison is base (02958f9) 95.65% compared to head (9a11923) 95.68%. Report is 84 commits behind head on master.

:exclamation: Current head 9a11923 differs from pull request most recent head 891b666. Consider uploading reports for the commit 891b666 to get more accurate results

Additional details and impacted files
@@            Coverage Diff             @@
##           master     #160      +/-   ##
==========================================
+ Coverage   95.65%   95.68%   +0.03%     
==========================================
  Files          28       28              
  Lines         943      951       +8     
  Branches       85       85              
==========================================
+ Hits          902      910       +8     
  Misses         34       34              
  Partials        7        7              

:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.

codecov[bot] avatar Mar 18 '21 18:03 codecov[bot]

@leongraumans I wonder if this PR is appropriate for merge? If this'll never be picked up, that's totally fine, please just let me know and I can continue to maintain this work in my fork. Thanks

rgs258 avatar May 11 '22 17:05 rgs258

Caught up to labd's master and added a new extension point: get_local_blocks()

rgs258 avatar Dec 19 '23 15:12 rgs258

@leongraumans I wonder if this PR is appropriate for merge? If this'll never be picked up, that's totally fine, please just let me know and I can continue to maintain this work in my fork. Thanks

bump, and thank you for maintaining this project!

rgs258 avatar Dec 19 '23 15:12 rgs258

Hi @rgs258,

Happy new year, and apologies for the late reply! I'll come back to you later this week.

leongraumans avatar Jan 02 '24 08:01 leongraumans

Added yet another extension point, get_form_block_class, to allow the return of subclass of a structural block for further control over the block class, such as overriding the clean() method to provide custom validation.

rgs258 avatar Jan 05 '24 19:01 rgs258

I think I might share that we're using this package in a somewhat unconventional way. We've adapted it such that Pages themselves are the definition of the form. That is to say, we've made a subclass of Page for which the body StreamField has as local blocks all of the form elements registered to this package (in addition to the usual subclasses of FieldBlock). With this, an content author may create a page that itself is a form, and they may define that form inline with the page content. The Page, and the entire definition of the form, exist within the normal Wagtail system of revisions, permissions, workflow, previews (that was fun), etc.. This gives our content authors a great deal of freedom and allows out site to host ~2200 unique forms.

Its a dream of mine to extract the non proprietary parts of our adaptation and open source them as a bolt-on to this package. ...just got to find the time :)

rgs258 avatar Jan 05 '24 19:01 rgs258

Adjusted wagtailstreamforms/wagtailstreamforms_fields.py to use new self.get_form_block_class() and self.get_local_blocks() methods

rgs258 avatar Jan 31 '24 21:01 rgs258