Module Builder - Unable to change field type
I added a custom Field of type Choices. I now want it to be of Short text type. I deleted the field and added it back as a Short text type. After I clicked the button "Update widget templates and finish" the type reverted back to Choices.
Hi David,
Recreating a field with the same name but different type is not as simple as it looks because it requires some heavy database manipulations. What I am suggesting is delete the choices field and save. Then open again the fields editor, add a field with same name and short text type and save. Avoid deleting and adding a field in the same phase, consider saving between these actions. This should work but in case you encounter some problems we have a knowledge base article that should help.
Feel free contacting us if you still have any problems.
Greetings,
Stoimen Stoimenov
the Telerik team
I did what you said and it worked. As you said the key is to delete the field and save it before re-adding it.
And what happens if you already have data defined in this column that you want to retain? I don't believe you can simply delete the column, and then re-add it (as the underlying data would also be deleted)...
For example, what happens if I had a custom field (of type short text), and originally associated with a 'custom' field (with a defined Virtual Path). However, suppose I now want to change the underlying virtual path to point to somewhere different)
Example: original virtual path was = 'SitefinityWebApp.Custom.Controls.MyFieldSelectorNamespace.MyFieldSelector' and now I want it to be 'SitefinityWebApp.Custom.Controls.MyNewFieldSelectorNamespace.MyFieldSelector'
Reasons to do this? Say in the original virtual path, I was using a standard asp.net DropDownList to render the values, and in the new virtual path, I was the telerik RadComboBox instead ... so basically the underlying code/purpose of the field is the same, just that it uses a different control to render the info...
Hope this makes sense. What would be the approach to take to change this around? Again, I want to keep the underlying data stored in the original field...
Hi,
Recreating the field as described in the KB article will be needed. To save the data tough export the data stored in the field that have to be changed or save the data in another field trough the API.
DynamicModuleManager dynamicModuleManager = DynamicModuleManager.GetManager();
Type iedcnewsType = TypeResolutionService.ResolveType(
"Telerik.Sitefinity.DynamicTypes.Model.Test.Test"
);
var liveItems = dynamicModuleManager.GetDataItems(iedcnewsType);
foreach
(var item
in
liveItems)
var fieldToBeDeletedValue = item.GetValue(
"FieldToBeDeleted"
);
//export to suitable format
//...
//copy this field data in another field, or a field created just for this purpose
item.SetValue(
"TemporaryStorageField"
, fieldToBeDeletedValue);
dynamicModuleManager.SaveChanges();
What about changing the type in the Administrators settings section? Is this going to cause problems down the road?
For reference I am talking about: Settings->Advanced->DynamicModules->Controls->"Your Model Dynamic Module" -> Views -> CategoryBackendEditView->Sections->MainSection->Fields->"Your field name"->FieldType
@Ryan
Sounds good, and will work...however any change to the module...ANY CHANGE in the UI will wipe out what you just did....like gets re-generated.
Interesting....How does that work? Where else is it storing what Custom Field Selector I initially specified?