Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7525877
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T03:40:30+00:00 2026-05-30T03:40:30+00:00

I have a CRUD form that has a select widget. The options in the

  • 0

I have a CRUD form that has a select widget. The options in the widget are dynamic. I cannot use tags, as the values are coming from other tables. I am trying to change the values in the controller using this method:

def change_widget(form, id, widget):
"Tries to find a widget in the given form with the given id and swaps it with the given widget"
for i in range( len(form[0].components) ):
    if hasattr(form[0].components[i].components[1].components[0], 'attributes'):
        if '_id' in form[0].components[i].components[1].components[0].attributes:
            if form[0].components[i].components[1].components[0].attributes['_id'] == id:
                form[0].components[i].components[1].components[0] = widget
                return True

return False

After I call the method and inspect the form, I can see that the form has been successfully modified. On the view side, I’m using a custom view and trying to display the form like so:

{{=form.custom.begin}} {{=form.custom.widget.customized_field}}
{{=form.custom.submit}} {{=form.custom.end}}

But, it still shows me the original unmodified widget. What am I doing wrong? Is there a better way to do this?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-30T03:40:32+00:00Added an answer on May 30, 2026 at 3:40 am

    First, here’s a much easier way to replace the widget:

    form.element(_id=id).parent[0] = widget
    

    However, because you are completely replacing the original widget with a new widget object rather than simply modifying the original widget, form.custom.widget.customized_field will still refer to the original widget. So, you have to explicitly replace form.custom.widget.customized_field as well. Try:

    def change_widget(form, name, widget):
        form.element(_name=name).parent[0] = form.custom.widget[name] = widget
    

    where name is the name of the field.

    See here for more about searching the server-side DOM.

    Also, note that you can specify a custom widget for the field before the form is even created, either within the table definition, or afterward:

    db.define_table('mytable', Field('myfield', widget=custom_widget))
    

    or

    db.mytable.myfield.widget = custom_widget
    

    Then when you create a form, the custom widget will be used rather than the default widget.

    See here for more about widgets.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have written a simple CRUD form which has one select list. However the
I have a basic CRUD form that uses PageMethods to update the user details,
I have a fairly large CRUD WinForm app that has numerous objects. Person, Enrollment,
I have a CRUD winform App that uses Merge Replication to allow disconnected functionality.
Okay I have a large CRUD app that uses tabs with Forms embedded in
I have a fairly large CRUD winform app that is set up to display
I have a class that provide the CRUD operation for an entity.Im using the
I have a parameterized hibernate dao that performs basic crud operations, and when parameterized
I have a web application that uses two databases. DB1 Users perform their CRUD
I have a pretty generic repository that does basic CRUD for many of my

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.