After a few days of head scratching I've managed to create a working fileupload Umbraco.forms.fieldtype with prevalue settings that can be manipulated by the form creator (in this instance file type and file size settings).
If anyone is puzzling how to do this, let me know I will post the code.
Happy to!
(quite simple when you know how!)
I would love to see how you did this. I'm trying to create a dropdownlist that sets prevalues from an external database, but reads from the database each time as the caching done with the current implementation of prevalue data is messing things up for me.
Hi Stefan, that does sound tricky. I am hardcoding the prevalues for my fileupload fieldtype, which is easier.
I think you would need to create a custom view for the prevalues that can handle the database work inline:
So set up the reference for the prevalues like so (at the top of your custom field type class in fieldtype.cs)
[Umbraco.Forms.Core.Attributes.Setting("preVals", alias = "prevals", prevalues = "", description = "my prevals description", view = "customddlprevals.html"]
public string preVals{get;set;}
The customddlprevals.html must be saved in App_Plugins/UmbracoForms/Backoffice/SettingsTypes
You prob already know this!
but then use an angular controller on customddlprevals.html to reference the class that will grab the required data from the database.
I've not had to do this myself, we've only had to call in values from a database for the cshtml page, which is very straightforward.
However, I think the solution provided in this stackoverflow answer I found here maybe a useful guide for how to set up your external class / angular controller and html (customddlprevals.html in this instance).
I've tried to show all my code to complete the custom file upload with prevalue editor settings below, had a lot of difficulty getting this to display in a way that makes sense. but essentially all the following should be in black boxes, to represent code (except for my comments).
To start, add the following to the App_Data/FieldTypes.cs:
public class myFUwithPre : FileUpload
{ //start parenthesis
Again sorry for the weird display can't seem to get this site to render all the code in a black box!
Finally under App_Plugins/UmbracoForms/Backoffice/Common/FieldTypes
create an html file (in this instance this should reflect the name you have given your custom control in the declaration so in this instance the file is called myfuwithpre.html.
< input tabindex="-1" type="file" />
< div class="inline-editor inline-textarea fieldset-prevals" ng-model="field.settings.preVals" placeholder="Please select required file type (leaving it blank will default to all allowed)">
Required file type: {{field.settings.preVals}}
< /div>
< div class="inline-editor inline-textarea fieldset-filesize" ng-model="field.settings.fileSize" placeholder="Please select required maximum file size" >
File size restricted to: {{field.settings.fileSize}} mb
< /div >
This gives the form author a message to show what file type and size options have been selected
Oops forgot to mention you will need to add two html files to App_Plugins/UmbracoForms/BackOffice/common/SettingsTypes:
in this instance I've called one bsfupre.html (that handles the prevalues for filetypes) and the other bsfupresize.html (these are referenced in the view properties of the Umbraco.Forms.Core.Attributes.Setting(s).
Thanks so much for this, it's very helpful. I kind of did something similar which was to create a helper class that queried data from the external source and then I used this in the fields view to get the prevalues and then populate the models preview values. I prefer your solution to this one though as I feel it better separates all the moving parts.
How to make a custom Forms property with prevalues
Hi all.
I cant find any documentation on how to create a custom Forms property with prevalues.
Can anyone help?
I found out.
There is a good guide here http://denisemdb.com/learn/umbraco-forms-custom-fieldtype/
I will post an exsample, others can use if they where stuck like i was.
CustomFieldType .cs
~/Views/Partials/Forms/Fieldtypes/CustomFieldType.thatRocks.cshtml
~/App_plugins/UmbracoForms/Backoffice/FieldTypes/CustomFieldType.html
After a few days of head scratching I've managed to create a working fileupload Umbraco.forms.fieldtype with prevalue settings that can be manipulated by the form creator (in this instance file type and file size settings).
If anyone is puzzling how to do this, let me know I will post the code. Happy to! (quite simple when you know how!)
Hi Karen,
I would love to see how you did this. I'm trying to create a dropdownlist that sets prevalues from an external database, but reads from the database each time as the caching done with the current implementation of prevalue data is messing things up for me.
Thanks,
Hi Stefan, that does sound tricky. I am hardcoding the prevalues for my fileupload fieldtype, which is easier. I think you would need to create a custom view for the prevalues that can handle the database work inline:
So set up the reference for the prevalues like so (at the top of your custom field type class in fieldtype.cs) [Umbraco.Forms.Core.Attributes.Setting("preVals", alias = "prevals", prevalues = "", description = "my prevals description", view = "customddlprevals.html"]
public string preVals{get;set;}
The customddlprevals.html must be saved in App_Plugins/UmbracoForms/Backoffice/SettingsTypes You prob already know this!
but then use an angular controller on customddlprevals.html to reference the class that will grab the required data from the database. I've not had to do this myself, we've only had to call in values from a database for the cshtml page, which is very straightforward.
However, I think the solution provided in this stackoverflow answer I found here maybe a useful guide for how to set up your external class / angular controller and html (customddlprevals.html in this instance).
https://stackoverflow.com/questions/45026383/how-to-call-external-class-into-angularjs-controller/45028512
I will post full examples of my code for the custom file uploader with file size and file type pre as soon as I can in case they are helpful as well.
I've tried to show all my code to complete the custom file upload with prevalue editor settings below, had a lot of difficulty getting this to display in a way that makes sense. but essentially all the following should be in black boxes, to represent code (except for my comments).
To start, add the following to the App_Data/FieldTypes.cs:
public class myFUwithPre : FileUpload { //start parenthesis
public myFUwithPre()
} //end parenthesis
Again apologies for the display on this this website had it's own ideas about how to display this, so I hope it still makes sense!
Add the custom view FieldType.myFUwithPre.cshtml in Views/Partials/Forms/Fieldtypes/Themes/Default/Fieldtypes with the following :
@using Umbraco.Forms.Mvc @model Umbraco.Forms.Mvc.Models.FieldViewModel
@if (Model.Values != null && Model.Values.Any()) {
Current File/s:
@foreach (string filePath in Model.Values) { var fileName = filePath.Split('/').Last();
}
@if (hasFileType || hasFileSize){
if (hasFileType){ strMessage = strMessage + " " + settings["preVals"].ToString() + " file type."; }
if (hasFileSize) { strMessage = strMessage + " " + settings["fileSize"].ToString() + "mb max file size."; }
Again sorry for the weird display can't seem to get this site to render all the code in a black box!
Finally under App_Plugins/UmbracoForms/Backoffice/Common/FieldTypes create an html file (in this instance this should reflect the name you have given your custom control in the declaration so in this instance the file is called myfuwithpre.html.
< input tabindex="-1" type="file" />
< div class="inline-editor inline-textarea fieldset-prevals" ng-model="field.settings.preVals" placeholder="Please select required file type (leaving it blank will default to all allowed)"> Required file type: {{field.settings.preVals}}
< /div> < div class="inline-editor inline-textarea fieldset-filesize" ng-model="field.settings.fileSize" placeholder="Please select required maximum file size" >
File size restricted to: {{field.settings.fileSize}} mb < /div > This gives the form author a message to show what file type and size options have been selected
Oops forgot to mention you will need to add two html files to App_Plugins/UmbracoForms/BackOffice/common/SettingsTypes: in this instance I've called one bsfupre.html (that handles the prevalues for filetypes) and the other bsfupresize.html (these are referenced in the view properties of the Umbraco.Forms.Core.Attributes.Setting(s).
The script for bsfupre.html is:
< ul > < li class="radiobuttonlist radio-inline fieldset-prevals" style="list-style-type:none !important;" ng-model="field.settings.preVals" ng-repeat="pre in setting.prevalues" > < label class="radio" > < input type="radio" name="checkboxlist" ng-model="setting.value" value="{{pre}}" /> {{pre}} < /label > < /li >< /ul >
// and the bsfupresize.html is:
< ul > < li class="radiobuttonlist radio-inline fieldset-filesize" style="list-style-type:none !important;" ng-model="field.settings.fileSize" ng-repeat="fs in setting.prevalues" > < label class="radio" > < input type="radio" name="radiobuttonlist" ng-model="setting.value" value="{{fs}}" /> {{fs}} mb < /label > < /li >< /ul >
I hope that is readable! I had to put a space after each < and before each > in order to get it to render on this web page.
Hi Karen,
Thanks so much for this, it's very helpful. I kind of did something similar which was to create a helper class that queried data from the external source and then I used this in the fields view to get the prevalues and then populate the models preview values. I prefer your solution to this one though as I feel it better separates all the moving parts.
Thanks heaps for the response.
You are most welcome! Very glad that it helped.
is working on a reply...