In the module for a custom ContentPart, how do I set a field to be a Text field?
In my migrations.cs class, I have created the table for the part:
public int UpdateFrom1()
{
SchemaBuilder.CreateTable("RightContentPartRecord", table =>
table.ContentPartRecord()
.Column<string>("Html"));
return 2;
}
So, I have a column called Html. I want to use the WYSIWYG editor, so I am told I need a Text field to get this to work "out of the box".
However, this isn't happening for me, so what do I need to do to turn my column called Html into a Text field on the part?
And how do I configure it to use the WYSIWYG editor?
If you want a property of your own custom contentpart to be displayed as a htmleditor, configure it as follows in the editortemplate of your part.
#Script.Require("OrchardTinyMce")
#Html.TextAreaFor(x => x.Header, new { #class = "html tinymce" })
In this case the 'Header' property is displayed as a html editor.
If you need this in more parts you can consider writing a Html extension or editor template for it.
A text field is not the same thing as a part property. Fields are not stored as their own database column. Here is an example of how you add a field to a part from a migration:
ContentDefinitionManager.AlterPartDefinition("Product",
builder => builder.WithField("ProductImage", fieldBuilder => fieldBuilder.OfType("MediaPickerField").WithDisplayName("Product Image")));
For text field, you'd also need to set the flavor setting by adding .WithSetting("Flavor", "html") to the field builder.
Related
I would like to display certain first level menuitem in bold.
This setting should be done by a checkbox when the user create / edit a menu item. (I have a workaround using the Model.Href, but it is not nice).
So I created a boolean field in Content definition / Menuitem URL (I don't know the name of the corresponding content definition in English Orchard).
How to access a custom field (Content Field) from a view?
(There already is a view which is used to customize the menu)
The examples I found use custom shapes, where the fields are accessed as built in fields (e.g. Model.ContentItem.FieldName ). But this is a different case.
With the help of "Piedone", the solution:
Model.Content.ContentItem.MenuItem.FieldTechnicalName.Value
Explanation
Examining the Model object in Visual Studio, the Model is a dynamic shape that have eg. Href property and a Content.
Content is a MenuPart, that is a content part that have a ContentItem property with the content item itself. Technically only content parts have Fields. When you (seemingly) add a field to a type it will be a part corresponding the type's name, that is MenuItem in this case (It's confusing that the display name of 'MenuItem' content type is Custom Link...)
The field's technical name is as you name it. When you add to a type, the Value will be a property of the BooleanField class. (By the way, it is nullable, so if you dont't save after adding the field, it will be null else the value you set).
I have a custom screen which contains a 'Details' Rich Text area that allows text to be shown as HTML, Plain Text, etc.
I also have a request to somehow be able to show that data on an Acumatica report. Unfortunately, even if the option for 'Plain Text' is selected, it still has formatting tags in the database field. Is there a type of field in the Acumatica report writer that can interpret data from that type of Rich Text field?
No it is not really possible until a rich text box control is added to the report designer.
The rich text control in Acumatica web page is mostly HTML.
If you change from VISUAL to HTML you can get the HTML code.
If you are very motivated you can attempt to inject hack the HTML in the report. It's a very bad idea but I managed to fool the designer into accepting HTML content as the navigate URL link content.
When the report is rendered in HTML mode the link control inherits some of the HTML styles on top of the link style. It's silly and useless but demonstrate the underlaying mechanisms needed to make rich text editor control happen in Acumatica report designer.
The alternative is to create a custom field that extracts the plain text:
#region DescriptionAsPlainText
public abstract class descriptionAsPlainText : PX.Data.BQL.BqlString.Field<descriptionAsPlainText> { }
private string _plainText;
[PXString(IsUnicode = true)]
[PXUIField(Visible = false)]
public virtual String DescriptionAsPlainText
{
get
{
return _plainText ?? (_plainText = PX.Data.Search.SearchService.Html2PlainText(this.Description));
}
}
#endregion
I created a Deposit module. My main goal with this module is to save some data on the DB.
I already made my custom type (Deposit) with my custom part (DepositPart) and it worked like I expected.
This DepositPart save the name, currency, liquidity, month, and url on the database.
But now I want to make a simple widget with 3 combobox and a button.
On those combobox I have some static text where the user can choose from. When the user hit the button I want to make a query and return a list with some Deposits and show only the name and the liquidity.
What is the best way to achieved this?
The best is creating your own controller.
For the part you have you can easily present as a widget adding some lines to migrations.
example:
(you can find more at this link: http://docs.orchardproject.net/Documentation/Writing-a-widget )
public int UpdateFrom1()
{
// Create a new widget content type with our map
ContentDefinitionManager.AlterTypeDefinition("MapWidget", cfg => cfg
.WithPart("MapPart")
.WithPart("WidgetPart")
.WithPart("CommonPart")
.WithSetting("Stereotype", "Widget"));
return 2;
}
Note that you simple add WidgetPart and add stereotype "Widget" to a new Content Type that also has yourpart (in this example MapPart).
For the result you may use a controller.
Having more information about your part I can help you more.
My question is simmalar to questions/10369967/orchard-cms-how-to-add-media-picker-field-to-anew-module
I've created a new content part, that has a select list, a text box and ... I want to include a media picker filed.
I have added this to the content part with Bertrand Le Roy's suggestion of:
ContentDefinitionManager.AlterPartDefinition("Product",
builder => builder.WithField("ProductImage",
fieldBuilder => fieldBuilder
.OfType("MediaPickerField")
.WithDisplayName("Product Image")));
However I've no idea of how to show this in my custom editor View
I'm sure there should be something easy like #Display(Model.ProductImage) ... but I've followed the writing a content part form the Orchard docs, and my model in my editor view is not dynamic.
So if such magic as #Display(Model.ProductImage) exists, how do I add the media picker item to my view model ?
Update
The Media picker field seems to be showing on the content types where I add this part, just not where I want it! I want to show / hide this field biased on values selected form a select list, How can I stop the default rendering of the field Content Item and Render it in my custom view ?
Update 2
I've added this in the model
public MediaPickerField MediaPicker
{
get{ return (MediaPickerField)((dynamic)ContentItem).HeaderPart.Image;}
}
this to the view
#Html.Partial("EditorTemplates/Fields/MediaPicker.Edit", Model.MediaPicker)
and this is the placement.info
<!-- MediaPicker -->
<Place Fields_MediaPicker_Edit="-"/>
Now it looks right on the editing via cms end... but dosen't seem to save the images to the database!
Should be something like #Model.ContentItem.Product.ProductImage.Url
i want to have a content type for my properties. let's name it 'my properties'.
and i have a taxonomy called 'my properties type' that contains 'books,shoes,clothes'.
the form for adding properties change on taxonomy selected item,because each of its type have different fields.
is it possible to have such content type in drupal ??
The solution within Drupal is to create separate content types for each property type. However, you can easily write some jquery to show/hide fields when taxonomy field is modified:
$('#your-taxonomy-dropdown').change(function() {
if($(this).val() == 'book') {
$('#field1').hide();
$('#field2').show();
}
});