最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

toolbar - 2sxc - how to use prefill in edit form - Stack Overflow

programmeradmin6浏览0评论

I'm trying to add an ephemeral field to pass in a prefill value and conditionally show or hide another field, as demonstrated here by Aaron Lopez

Using this example, I would pass a value to the toolbar like so

@Edit.TagToolbar(resume, prefill: new { VarShowPublished = false })

My data is loaded into a list of resumes. In the view I loop through each one with

@foreach(var resume in AsList(resumes as object)

My goal is an edit button for each data row.

The prefill doesn't work on edit. It will work on a 'new' but that's not my goal or what Aaron Lopez was able to do in his video.

I looked at some newer documentation on the 2sxc blog and tutorials and tried an updated Toolbar call

@Kit.Toolbar.Empty(resume).Edit(prefill: "VarShowPublished=false")

This also doesn't work when editing an existing data row. Am I missing something on how to get this to work on edit?

Cheers and thanks for the advice.

Update

I've figured out that setting the ephemeral field default value to 'false' and passing 'true' in the prefill does work. Using this I was able to achieve the result I need in the edit form.

Update 2

I still have a problem, but it's different now. To get the prefill to show I've updated the toolbar to be

@Kit.Toolbar.Empty(Content).Edit(prefill: "VarShowPublished=true").Delete().Settings(show:"always")>

Passing "Content" will give me the first item in the list, the same on every row. Passing "resume" will give me the correct content item for that row, but the prefill doesn't work.

I currently have 3 content items as revealed by Content.Count. When I pass an int to the Content object in the toolbar (such as Content[0], Content[1], Content[2]), passing 0 and 1 get me the correct content item to edit and the prefill works. But Content[2] throws an "index out of range" error. How can the index be out of range when the list has 3 items?

I'm trying to add an ephemeral field to pass in a prefill value and conditionally show or hide another field, as demonstrated here by Aaron Lopez https://wolfxmachina/blog/category/video/hide-and-show-edit-fields-in-2sxc-using-formulas

Using this example, I would pass a value to the toolbar like so

@Edit.TagToolbar(resume, prefill: new { VarShowPublished = false })

My data is loaded into a list of resumes. In the view I loop through each one with

@foreach(var resume in AsList(resumes as object)

My goal is an edit button for each data row.

The prefill doesn't work on edit. It will work on a 'new' but that's not my goal or what Aaron Lopez was able to do in his video.

I looked at some newer documentation on the 2sxc blog and tutorials and tried an updated Toolbar call

@Kit.Toolbar.Empty(resume).Edit(prefill: "VarShowPublished=false")

This also doesn't work when editing an existing data row. Am I missing something on how to get this to work on edit?

Cheers and thanks for the advice.

Update

I've figured out that setting the ephemeral field default value to 'false' and passing 'true' in the prefill does work. Using this I was able to achieve the result I need in the edit form.

Update 2

I still have a problem, but it's different now. To get the prefill to show I've updated the toolbar to be

@Kit.Toolbar.Empty(Content).Edit(prefill: "VarShowPublished=true").Delete().Settings(show:"always")>

Passing "Content" will give me the first item in the list, the same on every row. Passing "resume" will give me the correct content item for that row, but the prefill doesn't work.

I currently have 3 content items as revealed by Content.Count. When I pass an int to the Content object in the toolbar (such as Content[0], Content[1], Content[2]), passing 0 and 1 get me the correct content item to edit and the prefill works. But Content[2] throws an "index out of range" error. How can the index be out of range when the list has 3 items?

Share Improve this question edited Mar 21 at 20:31 Carl Roloff asked Mar 19 at 20:01 Carl RoloffCarl Roloff 253 bronze badges 2
  • What version of 2sxc (and DNN) are you using? Is this work being done within the Content App? If yes, what version? Can you show more of your code? I want to assume that your Resumes are a content type and that to display the list of them you are using a foreach loop? Considering 2sxc has gone from Dynamic, to Typed, to Strongly Typed, seeing more of your code would help us understand the context and give you a quicker answer. – Jeremy Farrance Commented Mar 25 at 0:55
  • Also, its not really an answer to your question, but my third answer on this page might give you some more ideas on how to tackle this. And it really highlights and shows off why we recommend using the "prefill as an object" format. The readability alone is such a significant win... accu4/2sxc/2SC-Toolbars/2SC-Toolbar-Examples - see the example under the heading, "Prefill, Tweak, and Useful Hover Details" – Jeremy Farrance Commented Mar 25 at 1:00
Add a comment  | 

1 Answer 1

Reset to default 0

Ephemeral

If you do use fields for the temporary value (more below), you must make it ephemeral. Otherwise it will only work once per content-item, since prefill only fills fields which are really empty. So if it's not ephemeral, the first time will end up adding data to the field, and the next open-operation will already have a value.

If you see that it's not working, my guess is you've been flip-flopping the field a few times and some have a value stored.

Form Parameters

About 2 years ago we added the ability to use form parameters, which are better for this kind of scenario. See https://docs.2sxc./api/dot-net/ToSic.Sxc.Edit.Toolbar.ITweakButton.html#ToSic_Sxc_Edit_Toolbar_ITweakButton_Filter_System_String_System_Object_. This then does not need a field, and can be accessed in the formula using data.parameters.yourNameHere. See https://2sxc./dnn-tutorials/en/razor/tut/formulas-parameters.

发布评论

评论列表(0)

  1. 暂无评论