Serenity: Change Title name of a field in a Dialog at runtime

Created on 20 Jul 2016  路  9Comments  路  Source: serenity-is/Serenity

Hey

how can I change a title of a field (eg Product Name to Product Internal Name) at runtime?.

I tried to get the field with jquery, but without succes.

and tried with this.form.field.getGridField() and this.form.field.element.closest(".field"), without success too.

Most helpful comment

Hi all,

I have made a WIKI article out of this with a generic solution which does not need a hard-coded "old value".

Hope this helps someone.

With kind regards,

John

All 9 comments

Do you mean on the dialog or the grid? And do you mean the title of the dialog or grid, or a property field on the dialog or grid?

  • Title of a Grid: On top of your XYZEntityRow.cs class declaration you will see an attribute that says DisplayName("PluralEntities"). Changing the string inside of this DisplayName() attribute will change what is displayed as the title of the grid
  • Title of a Dialog: Similarly, next to the DisplayName() attribute on top of your entity class declaration you will see an attribute InstanceName("SingularEntity"). The string inside of this InstanceName() attribute will be displayed as the title of a new dialog

For property fields on the grid, decorate the property field whose column name you want changed with a [DisplayName("Product Internal Name")] attribute directly above it:

// ....
public class ProductColumns
{
    [DisplayName("Product Internal Name")]
    public string ProductName { get; set; }

    // ....
}

You can do the same thing for property fields on the XYZEntityForm.cs class as well to change the label for fields on a dialog form.

Hey man !

I mean the title of a Dialog.

These step you told about is changing the title before the runtime. So, the title will be static. To change, I need to set the DisplayName property, build and run again.

I need to change the dialog field title during the runtime, when my user is editing the data.

Why? Here in Brazil we have 2 kind of ID: Personal ID (eg CPF), and Business ID (eg CNPJ).
to identify the name of Personal ID, my field title will show "NAME". But to identify Business ID, my field title must show "RAZAO SOCIAL", that is the name of the business registered in oficial documents.

Dialog has a dialogTitle property. Best place to set it is in updateTitle method of entity dialog.

It's not working..

I tried
this.form.RazaoSocial.getGridField().text('MUDEI O NOME!!!');

and
this.form.RazaoSocial.getGridField().text(function (i, oldText) {
return oldText === 'Nome' ? 'Raz茫o Social' : oldText;
});

but it replace all LINE to the changed text.

one idea that i have is how to get the id field at client side in run time (eg BELECH_Gestao_ClientesDialog10_NomeAbreviado)

What are you doing there. I said dialogTitle, not getGridField etc.

If you mean change title of field,

this.form.RazaoSocial.getGridField().find('.caption').text('asdadasd')

=)

Almost close !!!

So, the command above worked when the caption field is not a required field

this.form.RazaoSocial.getGridField().find('.caption').text('asdadasd')

but, if the caption is a required field, the command above not working well, because he will erase the "*" (signal of required field).

So, in these case to change the title of required field, the command below works good :

var texto = this.form.RazaoSocial.getGridField().find('.caption').prop('outerHTML').split('Raz茫o Social').join('Nome');
this.form.RazaoSocial.getGridField().find('.caption').prop('outerHTML', texto);

Thanks @jsbUSMC and @volkanceylan for your time and patience!

PS.: For some reason, In typescript, String.Replace only replaces first occurrence of matched string.

So, I used the function split(oldtext).join(newtext)

Hi all,

I have made a WIKI article out of this with a generic solution which does not need a hard-coded "old value".

Hope this helps someone.

With kind regards,

John

Was this page helpful?
0 / 5 - 0 ratings

Related issues

stixoffire picture stixoffire  路  3Comments

ga5tan picture ga5tan  路  3Comments

kilroyFR picture kilroyFR  路  3Comments

gfo2007 picture gfo2007  路  3Comments

AmuthaKondusamy picture AmuthaKondusamy  路  3Comments