Can anyone explain how to get conditional logic to work with a custom field ?
I have the following code and trying to add same http://www.nibble.be/?p=221 but cant even get the FieldConditionActionType.Show
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using Umbraco.Forms.Core;
using Umbraco.Forms.CodeFirst;
using Umbraco.Forms.Core.Controls;
using System.Web.UI.WebControls;
using Umbraco.Forms.Data;
namespace TestField
{
public class DCLabel : FieldType
{
[Umbraco.Forms.Core.Attributes.Setting("Allocation ", prevalues = "", description = "Enter the text to show in the label", control = "Umbraco.Forms.Core.FieldSetting.TextArea")]
public string LabelToShow { get; set; }
public System.Web.UI.WebControls.TextBox lblBox;
public Label _lblText;
public List<Object> Value;
public DCLabel()
{
//Provider
this.Id = new Guid("9a7ddf3d-442f-4537-8c73-13433007b029");
this.Name = "Custom Label Text Field";
this.Description = "A Read Only Field use to display Text ";
this.Icon = "Label.png";
this.DataType = FieldDataType.LongString;
Value = new List<object>();
}
public override List<object> Values
{
get
{
return Value;
}
set
{
Value = value;
}
}
public override WebControl Editor
{
get
{
_lblText = new Label();
_lblText.CssClass = "label-text";
_lblText.Text = umbraco.library.ReplaceLineBreaks(LabelToShow);
return _lblText;
}
set
{
base.Editor = value;
}
}
public override bool SupportsRegex
{
get
{
return false;
}
}
public override bool SupportsPrevalues
{
get
{
return false;
}
}
public override string RenderPreview()
{
return string.Format("<h6>{0}</h6>", umbraco.library.ReplaceLineBreaks(LabelToShow));
}
public override string RenderPreviewWithPrevalues(List<object> prevalues)
{
return RenderPreview();
}
}
}
[Umbraco.Forms.Core.Attributes.Setting("Allocation ", prevalues = "", description = "Enter the text to show in the label", control = "Umbraco.Forms.Core.FieldSetting.TextArea")]
[Umbraco.Forms.Core.Attributes.Setting("Allocation ", prevalues = "", description = "Enter the text to show in the label", control = "Umbraco.Forms.Core.FieldSetting.TextArea")]
public string LabelToShow { get; set; }
[FieldConditionRule("LabelToShow", FieldConditionRuleOperator.Is, "true")]
public string hidden { get; set; }
ok i see it's because the label fieldtype doesn't have an id assigned so the condition logic can't find it, should be easy to update will post details in a min, just need to test
Currently I am using Umbraco version 7.4.3 and as per instructions in various forums, I have uninstalled contour package and installed new umbraco forms.
Tried running package i.e. "Umbraco Forms Migration" to convert contour forms and workflows into Umbraco forms. But started getting error.
The type initializer for 'Nested' threw an exception.
at Umbraco.Forms.Core.Common.Singleton`1.getInstance() at Umbraco.Forms.Core.Providers.FieldTypeProviderCollection.getInstance() at Umbraco.Forms.Migration.Field.CreateFromDataReader(IRecordsReader reader) in c:\Users\timgeyssens\Documents\Visual Studio 2013\Projects\Umbraco.Forms.Migration\Umbraco.Forms.Migration\Contour\Field.cs:line 48 at Umbraco.Forms.Migration.Data.Storage.FieldStorage.GetAllFields(FieldSet fieldset) in c:\Users\timgeyssens\Documents\Visual Studio 2013\Projects\Umbraco.Forms.Migration\Umbraco.Forms.Migration\Contour\Data\FormStorage\FieldStorage.cs:line 93 at Umbraco.Forms.Migration.Data.Storage.FieldSetStorage.GetAllFieldSets(Page page) in c:\Users\timgeyssens\Documents\Visual Studio 2013\Projects\Umbraco.Forms.Migration\Umbraco.Forms.Migration\Contour\Data\FormStorage\FieldSetStorage.cs:line 44 at Umbraco.Forms.Migration.Data.Storage.PageStorage.GetAllPages(Form form) in c:\Users\timgeyssens\Documents\Visual Studio 2013\Projects\Umbraco.Forms.Migration\Umbraco.Forms.Migration\Contour\Data\FormStorage\PageStorage.cs:line 41 at Umbraco.Forms.Migration.Data.Storage.FormStorage.GetAllForms(Boolean archived) in c:\Users\timgeyssens\Documents\Visual Studio 2013\Projects\Umbraco.Forms.Migration\Umbraco.Forms.Migration\Contour\Data\FormStorage\FormStorage.cs:line 51 at Umbraco.Forms.Migration.MigrationService.Migrate(String connString) in c:\Users\timgeyssens\Documents\Visual Studio 2013\Projects\Umbraco.Forms.Migration\Umbraco.Forms.Migration\MigrationService.cs:line 26 at Umbraco.Forms.Migration.ContourToForms.Button1_Click(Object sender, EventArgs e) in c:\Users\timgeyssens\Documents\Visual Studio 2013\Projects\Umbraco.Forms.Migration\Umbraco.Forms.Migration\ContourToForms.ascx.cs:line 23
Then I checked the logs and found there are custom field types which are causing problem to this script
e.g. code
public sealed class CogFilteredUpload : FieldType
{
Enable Conditional Logic with Custom Field
Can anyone explain how to get conditional logic to work with a custom field ?
I have the following code and trying to add same http://www.nibble.be/?p=221 but cant even get the FieldConditionActionType.Show
Ok got this but doesnt seem to be working
Any suggestions on how to display a label using conditional logic ?
Comment author was deleted
Hey Fuji,
You can just use the UI, the attributes are used for code first forms...
Comment author was deleted
So no need to add extra code to the label fieldtype, you should just see the conditions bit in the UI for all fieldtypes/fields
Hi Tim,
Thanks but do you have any example not sure how to proceed. :(
Comment author was deleted
Add a field of type label to your field, then on the additional settings you should see the 'enable' conditions checkbox
Something like this ??
am getting confused now!!! do you mind showing what i need to add to the cs file ?
now that i can see Enable Condition on the form in contour, how do i get to make it to display "Label" only if a radioBox is checked?
Comment author was deleted
say you have a field of type radiobox with values yes/no
then on the label field you enable conditions and set it to show if all of the following match and then add a new rule
if radiobox field is yes , then hit the add
some more details here
https://umbraco.com/follow-us/blog-archive/2012/11/7/contour-30-features-conditional-logic.aspx
Comment author was deleted
So no need to update the cs file it is all done in the UI
Still no success Tim. Can you havea look at the source code ?
Comment author was deleted
Can you tell me the values of the radiobuttonlist and how you want to setup the condition?
Here you are... this is the custom fieldLabel. I would like to display the fieldLabel if "jj" is checked..
Comment author was deleted
thanks for the details, will give it a go
Comment author was deleted
ok i see it's because the label fieldtype doesn't have an id assigned so the condition logic can't find it, should be easy to update will post details in a min, just need to test
Comment author was deleted
In your label fieldtype view, add a surrounding div, that has the id set to @Model.Id, that should fix it
<div id="@Model.Id">
</div>
Comment author was deleted
or add the id to an existing element, if you post label view I can take a look
basic simple view
Comment author was deleted
ok easiest would be to add the id to the p tag so add id="@Model.Id"
Great looks like its working now.. thanks :)
Comment author was deleted
Super :)
Hi Tim,
Currently I am using Umbraco version 7.4.3 and as per instructions in various forums, I have uninstalled contour package and installed new umbraco forms.
Tried running package i.e. "Umbraco Forms Migration" to convert contour forms and workflows into Umbraco forms. But started getting error.
The type initializer for 'Nested' threw an exception.
at Umbraco.Forms.Core.Common.Singleton`1.getInstance() at Umbraco.Forms.Core.Providers.FieldTypeProviderCollection.getInstance() at Umbraco.Forms.Migration.Field.CreateFromDataReader(IRecordsReader reader) in c:\Users\timgeyssens\Documents\Visual Studio 2013\Projects\Umbraco.Forms.Migration\Umbraco.Forms.Migration\Contour\Field.cs:line 48 at Umbraco.Forms.Migration.Data.Storage.FieldStorage.GetAllFields(FieldSet fieldset) in c:\Users\timgeyssens\Documents\Visual Studio 2013\Projects\Umbraco.Forms.Migration\Umbraco.Forms.Migration\Contour\Data\FormStorage\FieldStorage.cs:line 93 at Umbraco.Forms.Migration.Data.Storage.FieldSetStorage.GetAllFieldSets(Page page) in c:\Users\timgeyssens\Documents\Visual Studio 2013\Projects\Umbraco.Forms.Migration\Umbraco.Forms.Migration\Contour\Data\FormStorage\FieldSetStorage.cs:line 44 at Umbraco.Forms.Migration.Data.Storage.PageStorage.GetAllPages(Form form) in c:\Users\timgeyssens\Documents\Visual Studio 2013\Projects\Umbraco.Forms.Migration\Umbraco.Forms.Migration\Contour\Data\FormStorage\PageStorage.cs:line 41 at Umbraco.Forms.Migration.Data.Storage.FormStorage.GetAllForms(Boolean archived) in c:\Users\timgeyssens\Documents\Visual Studio 2013\Projects\Umbraco.Forms.Migration\Umbraco.Forms.Migration\Contour\Data\FormStorage\FormStorage.cs:line 51 at Umbraco.Forms.Migration.MigrationService.Migrate(String connString) in c:\Users\timgeyssens\Documents\Visual Studio 2013\Projects\Umbraco.Forms.Migration\Umbraco.Forms.Migration\MigrationService.cs:line 26 at Umbraco.Forms.Migration.ContourToForms.Button1_Click(Object sender, EventArgs e) in c:\Users\timgeyssens\Documents\Visual Studio 2013\Projects\Umbraco.Forms.Migration\Umbraco.Forms.Migration\ContourToForms.ascx.cs:line 23
Then I checked the logs and found there are custom field types which are causing problem to this script
e.g. code
public sealed class CogFilteredUpload : FieldType {
}
Here FileUpload not working, which was a part of Umbraco.Forms.Core.Controls assembly earlier in Contour
Umbraco.Forms.Core.Attribute.Settings no more have Control attribute
Can you please help with alternate way on how we can fix custom fieldtypes created earlier, as those are used in most of our forms
Thanks, Snehal
is working on a reply...