Replace part of Display Name text while displaying in LabelFor - asp.net-core

I have a configuration that is saved in the database. I need to show that configuration in the label name. I am unable to use a replace functionality in the Razor view while fetching label value from Display Name.
Model Code:
[Display(Name = "SomeFooText XYZ typing speed")]
public decimal SomeFooText{ get; set; }
Something like below. I'm unable to find a code that would work for this scenario.
#Html.LabelFor(model => model.SomeFooText).Replace ("XYZ", model.configurationfromDB)
or
(<label asp-for="SomeFooText"></label>).Replace ("XYZ", model.configurationfromDB)
In worst case, I can move the code to c# and hardcode the "SomeFooText XYZ typing speed" and then use string.replace or use javascript to replace but just want to see if there is something that can be used on control directly.

Related

Form reset for all fields except one Vue.js

I'm trying to find a way to to exclude one field input in my form that is disabled and contains the value of a users ID number
I would like to know how I can tweak this.$refs.form.reset(); because it works perfectly but it clears EVERYTHING and I wish to contain the ID value and resets the rest of the fields like name surname age income etc
The reason why I the ID is important is that the user gives this in a sign-up step at the start and this form that I am talking about is located somewhere else to complete his profile I don't want to ask the user again to type his ID in again.
If anyone knows how to accomplish this it would be a great help
The reset method of the form simply looks at all the inputs bound to it and resets each one within a loop then empties the error bag, observe:
reset (): void {
this.inputs.forEach(input => input.reset())
this.resetErrorBag()
},
There's no reason you can't do the same, except for when they're disabled:
resetForm() {
this.$refs.form.inputs.forEach(input => {
if (!input.disabled) {
input.reset()
}
})
this.$refs.form.resetErrorBag() // necessary to remove validation errors after the field values are removed
}
Then you can call that function (against your Vue instance, not your VForm) with this.resetForm() and it should work out the way you want.
Disclaimer: Can't test it at the moment. input.disabled may not be readily available and may require further inspection of the input element.

DisplayFormat stops UK dates displaying in Chrome?

I have a property of my model as follows:
[DisplayName("Manufactured Date")]
[DataType(DataType.Date)]
[DisplayFormat(DataFormatString = "{0:dd/MM/yyyy}", ApplyFormatInEditMode = true)]
public DateTime? DateManufactured { get; set; }
In my scaffolded MVC Core view I have this code to display that value:
<input asp-for="LiftingItem.DateManufactured" class="form-control" />
In Chrome, the input shows the text "dd/mm/yyyy" and I get the error:
The specified value "09/02/2006" does not conform to the required
format, "yyyy-MM-dd".
Whereas in IE I get the actual date (e.g. "09/02/2006"). I think that difference is because Chrome is using the HTML 5 Date type input and so requires the format in "yyyy-MM-dd" format to display it?
If I remove the DisplayFormat attribute, sure enough it works in Chrome, but then in IE the date is in the wrong format ("yyyy-MM-dd" instead of "dd/mm/yyyy").
So, it seems like using DisplayFormat with a non "yyyy-MM-dd" format stops the Tag Helpers working? Is there any way to get it working nicely for both HTML 5 compatible and older browsers?
PS: I've also tried applying the formatting in the view instead using asp-format="{0:dd/MM/yyyy} as described in this question, but that also stops it working in Chrome.
Edit: I could also remove [DataType(DataType.Date)], but then I don't get the built in datepicker on HTML5 compatible browsers, which I would definitely like to on mobile devices.
Yes, you can combine the Tag Helpers with the DisplayFormat data annotation.
So, it seems like using DisplayFormat with a non "yyyy-MM-dd" format stops the Tag Helpers working? Is there any way to get it working nicely for both HTML 5 compatible and older browsers?
Just remove [DataType(DataType.Date)] from your model and the DisplayFormat(..) statement will start working as expected.
PS: I've also tried applying the formatting in the view instead using asp-format="{0:dd/MM/yyyy} as described in this question, but that also stops it working in Chrome.
You can combine the DisplayFormat(..) data annotation with the asp-format tag helper if you should require, in a specific view, a different date format than the one specified in your model.
If you have the following property in your model:
[DisplayName("Manufactured Date")]
[DisplayFormat(DataFormatString = "{0:dd/MM/yyyy}", ApplyFormatInEditMode = true)]
public DateTime? DateManufactured { get; set; }
and a view (a Detail view for instance) with the following line of code:
#Html.DisplayFor(model => model.DateManufactured)
Then you application will display dates having a format corresponding to the one specified with the data annotation, i.e. {0:dd/MM/yyyy}. Here's an example: 23/02/2017.
If you add in another view (an Edit view for instance) the following line of code (please note that I've added a 'M' to the month format):
<input asp-for="LiftingItem.DateManufactured" asp-format="{0:dd/MMM/yyyy}" class="form-control" />
Then the asp-format will take precedence over the model's data notation and your application users could type dates like this one: 23/Feb/2017 in the input box.

How to add Description using DescribedTaskRender - ObjectListView VB.net

I've been wondering how do I achieve something along the lines of this:
Task List
What I'm looking for is adding description under the title for example in the image the title is Setup Spy Camera and the description is 'Install spy camera blah blah blah'
I've read the documentation and I heard I'm supposed to use DescribedTaskRender. However I did not see any results. This is my code:
Public Class Shownames
Public Property Title As String
Public Property Description As String
Public Property Score As String
Public Property Episode As String
Public Property ID As String
End Class
Dim ShowItemCollection as Shownames
Showitemcollection.Title = ShowTitle
Showitemcollection.Description = ShowDescription
Showitemcollection.Score = ShowScore
Showitemcollection.Episode = ShowEpisode
Showitemcollection.ID = ShowID
ObjListview.addobject(ShowItemCollection)
I want ShowDescription to appear under Shownames. I've already named the DescriptionAspectName as Description but it still doesn't work. Can someone help me?
I also tried adding an image using imagelist using this: Imagelist1.Images.Add(Image.FromFile(Filepath))
but it doesn't show as well despite having associated the imagelist to describedtaskrender.
To use a DescribedTaskRender, you need to tell it what is the title, what is the description and which image each row should use. These are done, respectively, by setting AspectName, DescriptionAspectName and ImageAspectName.
You'll also need to increase the RowHeight so that both the title and the description can be seen. Set it to 60 for a first guess.
Finally, you'll need to set a name for your image when you add it. You then use that name to reference the image you added.
The demo has all of this stuff on display and in reasonable easy to understand code. This file should exactly how to do what you have asked: https://sourceforge.net/p/objectlistview/code/HEAD/tree/cs/trunk/Demo/TabDescribedTask.cs

How to create dropdownlist with static and dynamic values in Asp.net MVC with a divider between them

I want to create a dropdownlist which have three static values: Select All, Text Only, Numeric only. After that I like to add a line with some padding (just to separate these options) and then add some dynamic options.
I am not sure how to do this, Can some body please help?
So far I have created a List<SelectListItem> in my view model, and populated the static values from BLL. But I am not sure how to add a divider line in the middle now, and append some dynamic options after that.
Thanks
The normal select tag will not work like that, you will have to create custom dropdown using spans or divs.
See some examples here:
http://tympanus.net/codrops/2012/10/04/custom-drop-down-list-styling/

FormBlock Server Control in Ektron

I am working in Ektron 8.6.
I have a FormBlock Server Control in my Template Page,It is having a DefualutFormID of a valid HTML form from workarea.The form in the workarea have got few form fields and their corresponding values.
While the template page is rendering I need to GET those form field values and re-set them with some other values.
In which Page –Cycle event I should do this coding?
I tried this code in Pre-Render Event,but I am unable to GET the value there,but I am able to set a value.
I tried SaveStateComplete event as well,no luck.
String s=FormBlock1.Fields["FirstName"].Value;
If(s=”some text”)
{
// Re-set as some other vale.
FormBlock1.Fields["FirstName"].Value=”Some other value”;
}
In which event I can write this piece of code?
Page_Load works fine for changing the value of a form field. The default behavior is for the Ektron server controls to load their data during Page_Init.
The real problem is how to get the default value. I tried every possible way I could find to get at the data defining an Ektron form (more specifically, a field's default value), and here's what I came up with. I'll admit, this is a bit of a hack, but it works.
var xml = XElement.Parse("<ekForm>" + cmsFormBlock.EkItem.Html + "</ekForm>");
var inputField = xml.Descendants("input").FirstOrDefault(i => i.Attribute("id").Value == "SampleTextField");
string defaultValue = inputField.Attribute("value").Value;
if (defaultValue == "The default value for this field is 42")
{
// do stuff here...
}
My FormBlock server control is defined on the ASPX side, nothing fancy:
<CMS:FormBlock runat="server" ID="cmsFormBlock" DynamicParameter="ekfrm"/>
And, of course, XElement requires the following using statement:
using System.Xml.Linq;
So basically, I wrap the HTML with a single root element so that it becomes valid XML. Ektron is pretty good about requiring content to be XHTML, so this should work. Naturally, this should be tested on a more complicated form before using this in production. I'd also recommend a healthy dose of defensive programming -- null checks, try/catch, etc.
Once it is parsed as XML, you can get the value property of the form field by getting the value attribute. For my sample form that I set up, the following was part of the form's HTML (EkItem.Html):
<input type="text" value="The default value for this field is 42" class="design_textfield" size="24" title="Sample Text Field" ektdesignns_name="SampleTextField" ektdesignns_caption="Sample Text Field" id="SampleTextField" ektdesignns_nodetype="element" name="SampleTextField" />