Following on from an earlier question, I'm having problems using an Editor template for datetime fields, below is the code for the editor template (called "EditDateTime").
<%# Control Language="C#" Inherits="System.Web.Mvc.ViewUserControl<System.DateTime?>" %>
<%= Html.TextBox("", (Model.HasValue ? Model.Value.Date.ToString("dd/MMM/yyyy") :
DateTime.Today.ToString("dd/MMM/yyyy")), new { #class = "date" })%>
Here is the call to use the editor template,
<%=Html.EditorFor(Model => Model.StartDate, "EditDateTime") %>
All works ok, except the formatting is ignored. The Asp.Net MVC2 Framework book documents templates and specifically states
We’re passing an empty string for the name
parameter because the framework will automatically prefix this with the field name corresponding to the model item being rendered;
So I shouldnt need an id, so why is the formatting being ignored? HOWEVER - if I include an ID, the formatting is adhered to, BUT the model binding is then broken.
Help?
Just to clarify..
If I give the HMTL.Textbox an ID I get the following... The date format is correct but I lose the model binding as the ID is changed from "StartDate" to "StartDate_xx"
<input class="date" id="StartDate_xx" name="StartDate.xx" type="text" value="02/May/2012" />
And without the Id, it looks like this... model binding is correct but format is not.
<input class="date" id="StartDate" name="StartDate" type="text" value="05/02/2012 00:00:00" />
try using
Model.Value.ToString("dd/MM/yyyy")
works for me.
everything looks fine really... is the item you are sending a Datetime or a Datetime?
Related
In the below code model, fields are returning values, but when I try to render using #Html.Sitecore().Field it returns null. I would like those fields to be editable in the Experience Editor. How can I achieve this?
It is a controller rendering with a specified data source.
#using Sitecore.Mvc
#using Sitecore.Mvc.Presentation
#using Sitecore.Data
#model Project.Service.Models.Model
<div>
<h1>#Html.Sitecore().Field("Property Name")</h1>
<!--- Main header --->
<h4 class="text-danger"><em>
<span itemprop="streetAddress"> #Model.ProvinceName</span>,
<span itemprop="addressLocality">#Model.CityName</span>,
<span itemprop="addressRegion">#Model.ProvinceName</span>
#Model.PostalCode</em></h4>
I am new to Sitecore and any help or suggestion will be much appreciated.
You're trying to render the "Property Name" field from the context item. It probably doesn't have one. You'll need to tell your model what Item you're referencing and render it with something like #Html.Sitecore().Field("Property Name", Model.Item)
#Html.Sitecore().Field("Property Name") only works when your model is Sitecore.Mvc.Presentation.RenderingModel. You are using a custom model.
To use it in your case, you will need to pass in the item like this:
#Html.Sitecore().Field("Property Name", Item)
OR
you can also inherit IRenderingModel to your present model something like this
Model: IRenderingModel
If your model inherits IRenderingModel than your code will look like this:
#Html.Sitecore().Field("Property Name")
Please rate this answer up if this is helpful.
I have a component that includes a single Rich Text field. In the sublayout, the field is rendered as an Html.Editable with Glass so that it can be edited on the page in PageEditor. It looks like this:
public override void Initialize()
{
litBodyContent.Text = Html.Editable(GlassItem, item => item.Body);
}
<div style="min-height: 38px">
<asp:Literal runat="server" ID="litBodyContent" />
</div>
However, when I insert links using the Rich Text editor, when the page is rendered (in normal view after being published, not in page editor), the links are rendered with the item ID rather than the user friendly path, like this:
Go to another page
I am pretty sure that this is an issue with Glass. How can I keep the field editable in the Page Editor but make it render the link correctly?
You can check if you have proper attribute in the model.
If you have SitecoreFieldSettings.RichTextRaw attribute, it will NOT pass through render pipeline and returns the RAW HTML. Instead if you use Default (SitecoreFieldSettings.Default), rich text content will go through render pipeline and url will be in friendly format.
http://docs.glass.lu/html/d44739b2-5f0e-d862-f62c-86c50f0b262f.htm
Can you try to change it from using literal to use Editable() method directly, Something like:
<%= Editable(GlassItem, x => x.Body) %>
I think Initialize() is too soon in the page life cycle. Try moving it further along, like to Page_Load() or so.
Using standard sitecore controls (Link and Text), you can embed a text field within a link in the following way:
<sc:Link runat="server" Field="LinkUrl" >
<sc:Text runat="server" Field="LinkText" />
</sc:Link>
That will give you the ability to edit the text of one field and link of another field.
I have tried to replicate this using Glass, but have been unsuccessful. Something like this would be good (It doesn't work):
<%= Editable( x => x.LinkUrl,new { Text = Editable(Model,q => q.LinkText,null)}) %>
Is there another way of sorting this out?
There are two options I see if I cannot do this using standard glass functionality:
Change the GlassHtml code
Use Two Fields
If you are using Razor use this:
#using (BeginRenderLink(x => x.Link, isEditable: true))
{
#Editable(x => x.Title);
}
If you are using WebForms:
<%using(BeginRenderLink(x=>x.Link){ %>
<%=Editable(x=>x.Title) %>
<% } %>
Mike
If you are using Glass version 3, then you can't use Editable on Link and Image fields.
Use RenderLink and RenderImage instead.
See here: http://glass.lu/docs/tutorial/sitecore/tutorial22/tutorial22.html
The Editable method is the most basic method to use to make a field
editable and should be used with most fields that are page editable
except the Image field and General Link field
I am developing a Joomla 2.5 component. So I'm using Hello world example component for reference... In the edit view of the admin back end
<?php foreach($this->form->getFieldset('details') as $field): ?> <div>
<?php echo $field->label; echo $field->input;?> </div>
where the array $this->form->getFieldset('details') is stored.. and how to add new fields to the form that will store the data to another database table. where to change the fielda of the forms.
If you need to add more fields in your form then you can add new field in to the helloworld.xml browse to the following file on to
administrator->components->com_helloworld->models->forms->helloworld.xml
Open this file you will find the number of fields are listed over there you can add your own field by copy any of the field and rename it as you want.
You can also refer this link : J2.5:Developing a MVC Component/Adding backend actions
For example you want to add description field on to your form then you just need to add this line between the fieldset tag.
<field
name="description"
type="text"
label="COM_HELLOWORLD_HELLOWORLD_DESCRIPTION_LABEL"
description="COM_HELLOWORLD_HELLOWORLD_DESCRIPTION_DESC"
size="40"
class="inputbox"
default=""
/>
I would prefer you first read full tutorial of how to create MVC component for Joomla.Then you would be able to know how it works. Here the link :
J2.5:Developing a MVC Component/Developing a Basic Component
You may also use different form field type : Form field
I have been extensively searching for the answer but i cant seem to find one that works. I am using Django 1.4, with twitter boostrap 2.0.4 and i am trying to use date picker (eyecon) with no success. When i click on the input box no date box shows up.
<div id="due_date">
<input type="text" value="02/16/12" data-date-format="mm/dd/yy" id="datepicker" >
</div>
At the end of my base.html i have (right before closing the body):
<script src="/site_media/js/jquery.script.js"></script>
<script src="/site_media/js/bootstrap-datepicker.js"></script>
Finally on me jquery.script.js i have:
$(document).ready(function(){ $('.datepicker').datepicker()});
You have selected all elements who have the class "datepicker", while your input element definition does not have such a class but rather has datepicker as id attribute set.
Either select the id field $("#datepicker") or add a class ".datepicker" to your input field.
Do this: $(document).ready(function(){ $('#datepicker').datepicker()});
As you have set id="datepicker"
'.' is used for class and '#' is used for id