feat: replace x-editable with HTMX for inline editing#2847
feat: replace x-editable with HTMX for inline editing#2847hasansezertasan wants to merge 15 commits into
Conversation
Replace the unmaintained x-editable library with HTMX for inline editing in list views. The new implementation is theme-agnostic and works with any CSS framework (Bootstrap 4, Bootstrap 5, Tabler, etc.). Key changes: - Add HTMXEditableWidget replacing XEditableWidget (~125 lines reduced to ~30 lines). Backwards compatibility alias kept. - Add GET /ajax/edit/ endpoint returning edit form HTML fragments - Modify POST /ajax/update/ to return HTML fragments instead of plain text strings - Add editable_cell_display.html and editable_cell_edit.html fragment templates for HTMX swap targets - Add HTMX afterSwap handlers for select2 initialization and keyboard support (focus, Escape to cancel) - Vendor HTMX 2.0.8 (~14KB gzipped, MIT license) - Remove x-editable vendor files (CSS, JS, images) - Update tests for SQLAlchemy and Peewee backends - Update docstrings across all backends The column_editable_list API is unchanged. No user-facing breaking changes. Users who subclassed XEditableWidget can continue using the alias. Fixes pallets-eco#1615
f82da0a to
7567a9f
Compare
7567a9f to
7dd7c63
Compare
Add a kitchen-sink example demonstrating column_editable_list with all supported field types: String, Text, Integer, Float, Boolean, Date, Time, DateTime, Enum (Select), and ForeignKey (QuerySelect).
|
I'd be more into showing a modal for update forms. |
b0856bf to
9929fd3
Compare
- Fix E501 line length violations in widgets.py and base.py - Apply ruff formatting - Add type: ignore for get_list_value(None, ...) context arg
9929fd3 to
7c29db5
Compare
|
Wow!! You say test passed but how many are testing the actual code changes? |
Cover column_editable_list for the MongoEngine backend: - List view renders HTMX attributes - POST /ajax/update/ saves value and returns HTML fragment - Value persists after save - Non-editable field returns 404 - GET /ajax/edit/ returns edit form fragment - Relation (ReferenceField) editing works
56e79f2 to
4d943b5
Compare
Test BooleanField (set True via select, set False via absent field with field_name fallback), DateField/TimeField/DateTimeField widget restoration (datepicker/timepicker/datetimepicker), and missing pk/field parameter edge cases on ajax_edit endpoint.
4d943b5 to
0d5b90e
Compare
- Escape pk and field_name in HTMXEditableWidget hx-target to prevent XSS - Add can_edit authorization check to ajax_edit and ajax_update endpoints - Add scoped htmx:beforeSwap handler to display validation error responses - Add htmx:sendError handler with user feedback for network failures - Return HTML error fragments instead of plain text on all error paths - Guard cancel button against missing dataset.original with page reload fallback - Extract _restore_original_widget helper to deduplicate widget restoration - Add KeyError guard for missing field_name in form - Handle empty flash messages and empty validation errors with fallback text - Update stale FieldList references in docstrings and comments - Remove redundant entries from keep set and identity list comprehension
…ape) Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
- Use position:fixed popover below the cell instead of inline swap - Append popover via hx-swap=beforeend so cell content stays visible - Add JS positioning using getBoundingClientRect for viewport coords - Add close-before-open, click-outside, Escape key, cancel button - Style editable cells with blue text and dashed underline - Match x-editable spacing: Bootstrap popover padding, larger buttons - Add textarea min-height (5 rows) matching x-editable defaults - Remove unused popover-title and popover-buttons CSS - Simplify closeEditablePopover to just remove the popover element
- Fix line too long (89 > 88) in error message formatting - Change type: ignore[misc] to type: ignore[arg-type] for get_flashed_messages - Fix list-item type error by using list() on field.errors - Make IntegerField test assertion compatible with older WTForms
|
Also, this looks like a breaking change to me. If that's the case should either release this in 3.0, or provide a variable/parameter to switch. |
Could you please provide more detailed information 🤓?
I taught the same. The breaking change to me seemded like "XEditableWidget", so I did a quick search for Is it possible to determine if it's a breaking change or not? |
|
Some LLM: I did a GitHub-wide search for The backwards compatibility alias is already in place: # flask_admin/model/widgets.py:113
XEditableWidget = HTMXEditableWidgetSo The one theoretical breaking case: someone who subclassed The alias can be removed with a deprecation warning in a future major version if desired. |
|
Comment from the sideline - sorry - none of this is yet me weighing in on whether I support this change or not (or have even understood it yet!).
I did a non-LLM GitHub-wide search for this and I did find some external uses, eg:
That said, these codebases haven't been touched in a while. I think should recognise that this isn't a backwards-compatible change and decide what level of risk tolerance we have for doing this without a full deprecation cycle. This comment isn't meant to steer strongly in either direction. You can decide that we prioritise our own speed in merging this over breaking one or two people, or you can decide that we try to stick with a stricter deprecation policy. Do you have thoughts on how much overhead we're looking at if we deprecate this through adding a new component and leaving the existing XEditableWidget untouched? |
|
maybe the right question is, why we are stricting to deprecate something that is already not supported, not functioning well, not compatible for future UIs ? to me, our users would be happy if we provide them a better, stable, and permenant solution with a little cost of breaking change. |
|
Because we are supporting it by having it in Flask-Admin. When a project takes on a dependency it's an implicit commitment to supporting that for our users, even if it is deprecated upstream. It's not fun for users when projects make breaking changes without giving adequate warning or time to migrate. In my opinion this is simply the cost of providing stable software for an ecosystem. I think there's potential to say the benefits of just swapping out directly outweigh the risks/disruption for users, but that isn't a decision to make without some consideration or understanding of the impact. None of this is to say that I couldn't be convinced that just doing a straight swap here will be 'fine', so consider all of this commentary/conversation rather than edict. |
Actually, the issues I had with x-editable at #2444 motivated me to work on this. I've used skycyclone/x-editable over there, but that hasn't received any updates in the last 5 years either. That got me thinking about alternatives, and I gave HTMX a try — it worked! 🥂 I did have to add some CSS to make it look a bit more polished, though. I believe this work is a stepping stone toward better custom theme support.
After giving it more thought, I agree with you — this is not a backwards-compatible change. I think we should discuss the deprecation policy and our vision for the user interface further before moving forward.
The idea that led me to this PR: dropping Bootstrap 4 is overhead in itself. I think we should talk about this topic thoroughly — what we want to do, where we want to go, and what we want to achieve. |
|
I think making this not a breaking change is not possible (correct me if I am wrong), but I agree the "breaking" is minor.
|
|
After thinking about this more and reading everyone's feedback, I'd like to propose Option 1 with a twist. Instead of tying the HTMX inline editing to a BS5/tabler theme (which depends on PR #2643), I'm proposing a "vanilla" theme — a dependency-free foundation that uses only semantic HTML, minimal custom CSS, and HTMX as the sole JS dependency. No jQuery, no Bootstrap, no Font Awesome. I explored this idea through a brainstorming session with Claude Code (Opus), where I guided the design decisions and it helped me think through the architecture and write up the spec. Why vanilla?
To demonstrate adoptability, I'd also ship a "picocss" theme alongside it — extending the vanilla templates and just swapping in PicoCSS (~10KB classless CSS). If the vanilla HTML is truly semantic, PicoCSS should "just work" with minimal overrides. BS4 stays untouched and remains the default. The original There's a full design spec behind this. Happy to share if there's interest in discussing the details. Thoughts? Of course this is just an idea, the possible output might not be exactly like that. |
I'm really in favour of this idea. It's been in the very back of my mind (in a very light way) that it would be nice if Flask-Admin had a very clear 'theming' API/interface that was well defined to support all of the actions needed for this vanilla API, and then use that. I think it would be great if themes for Flask-Admin could be published as separate packages and then just 'plugged in'. I suspect this requires quite a lot of up front thinking through and would be a big undertaking. While working on a theme myself for some work projects I did have to mangle quite a lot of things and hit some flask-admin internals, so it's not a very clean process. Right now a lot of the functionality required for bootstrap is fairly closely integrated/coupled with flask-admin internals itself, so it'd be really great to detangle some of that. I'd also strongly prefer that any new 'vanilla' theme we work towards is progessively enhanced, ie resilient to failures in JS (following best practice principles from eg GOV.UK: https://www.gov.uk/service-manual/technology/using-progressive-enhancement - I'm aware this is my specific context a lot of the time, but I think still a strong foundation). UX improvements should ideally be layered on top of that to provide a more full and modern experience. |
|
I agree with everything you are saying, but we already have closed PR and open PRs just to bring a new theme, and this suggestion increases the workload without bringing us further. My personal opinion is that we should push to get a bootstrap5/tabler whatever template, and then we can refactor from there. |
|
That approach is fine with me! |
Summary
column_editable_listAPI is unchanged — no user-facing breaking changesFixes #1615
Changes
XEditableWidget(125 lines, 12+ field type mappings)HTMXEditableWidget(30 lines, field-agnostic)afterSwaphandlersPOST /ajax/update/→ plain textGET /ajax/edit/(new) +POST /ajax/update/→ HTML fragmentsHow it works
GET /ajax/edit/?pk=X&field=Y<td>POST /ajax/update/Why HTMX
Test plan
test_ajax_edit_endpointcovers: valid field, non-editable field (404), non-existent record (404), nocolumn_editable_list(404)Manual testing
Run the "sqla_column_editable" example to test inline editing interactively.
What to test manually