https://avo.cool logo
Join Discord
Powered by
# avo-2
  • n

    narrow-laptop-54609

    05/24/2022, 5:34 PM
    @lemon-wall-20836 Yes, I'm using that. I'm getting this error though: "Uncaught DOMException: Failed to execute 'define' on 'CustomElementRegistry': the name "trix-toolbar" has already been used with this registry"
  • l

    lemon-wall-20836

    05/24/2022, 5:34 PM
    you can just copy eveything from the current trix field
  • l

    lemon-wall-20836

    05/24/2022, 5:34 PM
    hmmm
  • l

    lemon-wall-20836

    05/24/2022, 5:34 PM
    not sure about that error
  • l

    lemon-wall-20836

    05/24/2022, 5:34 PM
    let me check if you can have two trixs' on one page. but I think you can
  • n

    narrow-laptop-54609

    05/24/2022, 5:34 PM
    https://github.com/basecamp/trix/issues/247
  • n

    narrow-laptop-54609

    05/24/2022, 5:36 PM
    I tried that solution but it doesn't work. So just a bit of context, on my resource I have field for trix editor. I want to customize the toolbar of that trix. I won't be using it somewhere else or with another field.
  • n

    narrow-laptop-54609

    05/24/2022, 5:37 PM
    Getting the same error message...
  • l

    lemon-wall-20836

    05/24/2022, 5:38 PM
    it seems that it is possible to have two trix editors
  • l

    lemon-wall-20836

    05/24/2022, 5:38 PM
    so I think it's best if you create a custom field and mount trix by yourself in that new field
  • l

    lemon-wall-20836

    05/24/2022, 5:38 PM
    as opposed to add new buttons to this field
  • l

    lemon-wall-20836

    05/24/2022, 5:39 PM
    I don't mind either approach, but TBH I think the first one is the better option
  • l

    lemon-wall-20836

    05/24/2022, 5:39 PM
    https://github.com/avo-hq/avo/blob/main/lib/avo/fields/trix_field.rb https://github.com/avo-hq/avo/blob/main/app/components/avo/fields/trix_field/edit_component.html.erb https://github.com/avo-hq/avo/blob/main/app/components/avo/fields/trix_field/edit_component.rb
  • l

    lemon-wall-20836

    05/24/2022, 5:40 PM
    and this for custom fields https://docs.avohq.io/2.0/custom-fields.html
  • n

    narrow-laptop-54609

    05/24/2022, 5:43 PM
    @lemon-wall-20836 Thanks for the help! So you are suggesting that I created a custom field, attach trix to it and then customize the toolbar?
  • l

    lemon-wall-20836

    05/24/2022, 5:43 PM
    yes. exactly that👆
  • l

    lemon-wall-20836

    05/24/2022, 5:43 PM
    I would go that route
  • l

    lemon-wall-20836

    05/24/2022, 5:44 PM
    then, if everything pans out and asses what needs to be done, we can add some kind of API to inject that into the default trix field for everyone (and your use-case too)
  • n

    narrow-laptop-54609

    05/24/2022, 5:44 PM
    K, I'll try that. Thanks again!
  • l

    lemon-wall-20836

    05/24/2022, 5:44 PM
    for sure! my pleasure 🤙
  • l

    lemon-wall-20836

    05/24/2022, 5:45 PM
    not sure if you're here to make friends, but we have an #740900436722188401 channel where we say something about ourselves. all good if you're not interested ✌️
  • n

    narrow-laptop-54609

    05/24/2022, 5:46 PM
    @lemon-wall-20836 Will do. Thanks!
  • d

    dazzling-lighter-36143

    05/25/2022, 5:55 AM
    👋 Hey ya'll! I'm new to Avo, and i've been trying to play with some of the functionality around associations. One of the things i'm trying to do is pre-populate fields from an associated model in the
    new
    view. For example, I have a resource
    baz
    , which has the field
    field :foo, as: :has_many, through: bars
    . When I create a new
    foo
    by clicking
    Create new foo
    on the
    baz
    resource
    show
    view, I would like to pre-populate some of the default values for the new
    foo
    fields from the existing
    baz
    . Based on my review of Avo's source, it looks like I can scrap together a solution to this by setting a context with
    params
    available, then querying
    baz
    by reconstructing an instance of the
    baz
    model from the query parameters:
    via_relation=bazs&via_relation_class=Baz&via_resource_id=1
    within the resource definition, effectively using the method Avo's
    BaseController
    uses: https://github.com/avo-hq/avo/blob/0fc1f9553acc465e0870aab3ece2e70008f0f4c1/app/controllers/avo/base_controller.rb#L366-L368. Would there happen to be a cleaner way to do this?
  • l

    lemon-wall-20836

    05/25/2022, 8:36 AM
    Hey @dazzling-lighter-36143 You could use the
    default
    field option. you can use it as a block and access the params through
    Avo::App.params
  • l

    lemon-wall-20836

    05/25/2022, 8:38 AM
    Copy code
    ruby
      field :level, as: :text, default: -> {
        # Use the params or context object to set a default
        puts Avo::App.params.inspect
        puts Avo::App.context.inspect
        "yes"
      }
  • l

    lemon-wall-20836

    05/25/2022, 8:38 AM
    you can also use the context object for more information
    Avo::App.context
  • l

    lemon-wall-20836

    05/25/2022, 8:38 AM
    https://docs.avohq.io/2.0/customization.html#context
  • l

    lemon-wall-20836

    05/25/2022, 8:39 AM
    I think you have all you need to pre-populate the field
  • l

    lemon-wall-20836

    05/25/2022, 8:50 AM
    Generally speaking, the generated controllers (eg:
    Avo::ProductsController
    for
    ProductResource
    ) are there just for Rails to know how to generate the routes.
  • l

    loud-jewelry-99127

    05/25/2022, 11:21 AM
    Pro tip : if you want to pré populate a action use a lambda function on default field option
1...383940...64Latest