0

How to apply * after form label from jqgrid through mvc3 model, like ex:-Username:*. I want label suffix like element suffix from form options. How can I create label suffix in form options

  • 2
    I am unclear what you are asking? You want a suffex where? In the grid? In a column name? In the grid caption? What form are you speaking of? – Mark Jan 21 '13 at 14:14
  • Thanks Mark for response. What I mean is I want the asterisk symbol after label(Name) but not before textbox as you shown. In above example you shown it disturbs the allignment of the controls also. Example- Name:* TextboxControl Date:* TextboxControl Ship Via: DropdownControl The label names (Name,Date)are loaded dynamically. – user1997213 Jan 22 '13 at 09:15
  • My labels are dynamically loaded from database, not set using label attribute. So I want the form labels are suffixed with * which are different from column heades in jqgrid. Please find below code I am using to set column headers and formlabels dynamically. //This line updates the ColNames array through jqGrid. If done this way the edit form will also use those names. // This trick will not work if we have set the FormLabel property in the JqGridColumnEditable attr in the Entity Model. $(gridId).jqGrid("setLabel", fieldLablesData[i].ColumnName, fieldLablesData[i].CustomLabel); – user1997213 Jan 22 '13 at 10:13

1 Answers1

2

It's really difficult to understand what you exactly mean. If I understand you correctly you can use label property of formoptions to solve your problem. The value of label property could be any common HTML fragment. For example the setting below

formoptions: {
    elmprefix:"&nbsp;&nbsp;(<span class='mystar' style='color:red'>*</span>)&nbsp;",
    elmsuffix:"&nbsp;&nbsp;yyyy-mm-dd",
    label: "<span>Date<span><span style='float:right'>XXX</span>"
}

set two spans as the label of the form. As the result you can produce forms like below (see the field Date)

enter image description here

UPDATED: The usage of formoptions.label or formoptions.elmprefix are two way which you can use. If you want to set formoptions.label with any dynamical values you can do this with respect of $(this).jqGrid("setColProp", "yourColumnName", {formoptions: {label: "any HTML or text string"}}). If you would make the call inside of beforeInitData callback (like in the answer) jqGrid will use new modified labels in the form. You should don't forget to use recreateForm: true option of the form editing (see here examples).

Community
  • 1
  • 1
Oleg
  • 220,925
  • 34
  • 403
  • 798
  • Thanks Oleg for your reply. What I mean is I want the asterisk symbol after label(Name) but not before textbox as you shown. In above example you shown it disturbs the allignment of the controls also. Example- UserName:* TextboxControl – user1997213 Jan 22 '13 at 08:05
  • @user1997213: I suggested you to use **`label`** property (see "XXX" part in the form). It allows you to place **any information** on the place of label. You can use multiple ``, `
    ` and so on. Using CSS you can do what you want. Additionally I shown that one can use `elmprefix` to place any information *before* controls. If you would use `elmprefix` with some spaces (` `) for all other fields then you will have the same results like placing `*` at the end of `label`. So I tried to show you *multiple* ways to solve your problem.
    – Oleg Jan 22 '13 at 08:17
  • My labels are dynamically loaded from database, not set using label attribute. So I want the form labels are suffixed with * which are different from column heades in jqgrid. Please find below code I am using to set column headers and formlabels dynamically. //This line updates the ColNames array through jqGrid. If done this way the edit form will also use those names. // This trick will not work if we have set the FormLabel property in the JqGridColumnEditable attr in the Entity Model. $(gridId).jqGrid("setLabel", fieldLablesData[i].ColumnName, fieldLablesData[i].CustomLabel); – user1997213 Jan 22 '13 at 10:10
  • @user1997213: Look at the "**UPDATED**" part of my answer. – Oleg Jan 22 '13 at 10:35
  • Ok Great. But how to identify the required field of all properties(to give columnname as tr_columnname) on form load.I am unable to identify what are the fields marked with [Required] attribute in Model on form load. – user1997213 Jan 22 '13 at 10:44
  • @user1997213: I'm not sure that I understand you correctly. If you have information which you need on the server side you can send in as the part of JSON response from the server. Inside of `beforeProcessing` or `loadCompleted` callbacks you will have full access to all information from the server response. So you can either change `formoptions.label`, `editrules.required` or any other column settings directly inside of the callbacks or you can save required information in a variable and use it whenever it will be needed. – Oleg Jan 22 '13 at 11:12
  • Thank You Oleg for your responses. The below code did trick for me. function markRequiredFields(gridName) { var colmodel=$(gridName).jqGrid('getGridParam', 'colModel'),i=0,l=colmodel.length; for (i=0; i < l; i += 1) { if(colmodel[i].hasOwnProperty("editrules") && colmodel[i].editrules.hasOwnProperty("required") && colmodel[i].editrules.required ===true ){ $('#tr_'+colmodel[i].name+ ' td.CaptionTD').append('*'); } } } – user1997213 Jan 22 '13 at 14:05