How to show fields mendatory in editor.

How to show fields mendatory in editor.

arunsingharunsingh Posts: 7Questions: 0Answers: 0
edited December 2013 in Editor
Hi Allan,

First of all, thanks for making wonderful Datatable and Editor. I am using that first time in my project.
I want to show some fields as mendatory with "Red Star" sign or something like that. Could you please help me out.

Thanks in advance.

Replies

  • allanallan Posts: 63,531Questions: 1Answers: 10,475 Site admin
    You could use the `label` option ( https://editor.datatables.net/fields/#label ) and just add the * in there. So might might do:

    [code]
    label: 'Name *:'
    [/code]

    The other option is to use the `className` option ( https://editor.datatables.net/fields/#className ) and assign a CSS background to the element.

    Regards,
    Allan
  • arunsingharunsingh Posts: 7Questions: 0Answers: 0
    Thanks a lot Allan. First one is working great for label. It is showing '*' sign after the label text of the textbox.
    But I just want to use '*' after textbox not after the label text of that textbox.

    I would appreciate if there is any help for this.

    Regards,
    Arun Singh
  • allanallan Posts: 63,531Questions: 1Answers: 10,475 Site admin
    Hi Arun,

    Two options:

    1. A little bit of CSS and the `className` option I mentioned above:

    [code]
    .required input:after {
    content: "*"
    color: red
    }
    [/code]

    Or by DOM manipulation: what you could do is use the `node()` method ( https://editor.datatables.net/api/ ) and jQuery's appendAfter - something like:

    [code]
    $('*').appendAfter( $('input', editor.node('myField') );
    [/code]

    So what is happening is `editor.node('myField')` is getting the DOM element for the field of that name, and the jQuery selector getting the input element and the new span tag being added.

    The CSS option is probably easier, but it won't work on old IE browsers.

    Allan
  • arunsingharunsingh Posts: 7Questions: 0Answers: 0
    Thanks again Allan!! I tried 2nd option but it gives error that there is no such method for [quote]node()[/quote]. But its ok, I will do it with first option with CSS.

    Regards,
    Arun Singh
This discussion has been closed.