ability to specify datatype explicitly

1 Answer 59 Views
Form
Aleksandr
Top achievements
Rank 1
Bronze
Bronze
Veteran
Aleksandr asked on 09 Jan 2023, 04:54 PM

need to have the ability we have in a grid, to set the field to "string" or object EXPLICITLY 

 

P.S seems right now it is under self determination based on fields value & if the field is null & editor DropDown, the object will be set instead of just value

1 Answer, 1 is accepted

Sort by
0
Accepted
Georgi Denchev
Telerik team
answered on 12 Jan 2023, 11:07 AM

Hi, Aleksandr,

The data type of the fields can be set through the underlying dataSource schema configuration:

dataSource: {
                     schema: {
                        model: {
                            id: "ProductID",
                            fields: {
                                ProductID: { editable: false, nullable: true },
                                ProductName: { validation: { required: true } },
                                UnitPrice: { type: "number", validation: { required: true, min: 1} },
                                Discontinued: { type: "boolean" },
                                UnitsInStock: { type: "number", validation: { min: 0, required: true } }
                            }
                        }
                    }
}

Best Regards,
Georgi Denchev
Progress Telerik

Love the Telerik and Kendo UI products and believe more people should try them? Invite a fellow developer to become a Progress customer and each of you can get a $50 Amazon gift voucher.

Aleksandr
Top achievements
Rank 1
Bronze
Bronze
Veteran
commented on 12 Jan 2023, 03:39 PM

Hello Georgi,

 

please confirm that it is possible, I am looking at the forms API doc & can't see a data source option:

https://docs.telerik.com/kendo-ui/api/javascript/ui/form?_ga=2.158395000.336107526.1673130214-1931469790.1620243254&_gl=1*1e1i6e3*_ga*MTkzMTQ2OTc5MC4xNjIwMjQzMjU0*_ga_9JSNBCSF54*MTY3MzUzNzg0MC44Ni4xLjE2NzM1Mzc4NTQuNDYuMC4w

 

Georgi Denchev
Telerik team
commented on 17 Jan 2023, 10:16 AM

Hi, Aleksandr,

My apologies about the misunderstanding on my end.

No, it isn't possible to explicitly set a "field" type in the Form component.

However, the described problem could be potentially resolved by configuring the valuePrimitive option of the DropDownList.

You can set it through the editorOptions of the Form field.

When valuePrimitive is set to true, the model will be updated with the value from the dataValueField. When it is set to false, the model is updated with the entire object.

Let me know if this works for you.

Best Regards,

Georgi

Aleksandr
Top achievements
Rank 1
Bronze
Bronze
Veteran
commented on 17 Jan 2023, 06:44 PM | edited

Hello Georgi,

thx a lot for your advice, value primitive should work. In addition, if my request could be taken as a future request, it would be great, seems just a few tweaks to the forms control could make it perfect & a little bit more manageable

Thx Alex

 


Georgi Denchev
Telerik team
commented on 20 Jan 2023, 03:22 PM

Hi, Alex,

We can certainly open a FR, however may I ask you to clarify a bit more about what the expected result is?

What should happen if you tell the form field.type = "string" when the default value in the formData is a number? Should it change the editor to a TextBox instead of NumericTextBox?

Best Regards,

Georgi

Aleksandr
Top achievements
Rank 1
Bronze
Bronze
Veteran
commented on 20 Jan 2023, 03:25 PM

exactly, the good example is a nullable bool (bool?), now if it is null you show a textbox instead of a checkbox, but if specify the type as a boolean, you will show the right control
Georgi Denchev
Telerik team
commented on 25 Jan 2023, 12:24 PM

Hi, Alex,

I've synced with the Devs regarding this functionality and it looks like it is already possible to do what the schema.model of the dataSource does.

Take a look at the following example:

    <form id="myForm"></form>

    <script>
      $("#myForm").kendoForm({
        formData: {
          ID: 1,
          Date: kendo.toString(new Date(), "MM/dd/yyyy"), // String date
          Number: "54" // String number
        },
        items: [{
          field: "Date",
          label: "Date:",
          editor: "date", // Set the editor to "date" like you would do in a dataSource schema model.
          validation: { required: true }
        }, {
          field: "Number",
          label: "Number:",
          editor: "number" // Set the editor to "number" like you would do in a dataSource schema model.
        }]
      });
    </script>

Dojo

https://dojo.telerik.com/@gdenchev/ijOYeyeh 

Let me know what you think.

Best Regards,

Georgi

Aleksandr
Top achievements
Rank 1
Bronze
Bronze
Veteran
commented on 25 Jan 2023, 01:56 PM

Georgi,

 

this is exactly i have asked for, seems the documentation needs to be updated, here completely diff chose for editors

 

Defines the editor widget type. Available options are:

  • DropDown widgets - "AutoComplete", "DropDownList", "ComboBox", "MultiSelect", "DropDownTree", "MultiColumnComboBox"
  • DatePicker widgets - "DateInput", "DatePicker", "DateTimePicker", "TimePicker"
  • Input widgets - "TextBox", "TextArea", "NumericTextBox", "MaskedTextBox", "RadioGroup", "CheckBoxGroup", "Switch", "Rating", "Slider", "ColorPicker", "ColorGradient", "ColorPalette", "FlatColorPicker", "Signature", "hidden"
  • Editor widget - "Editor"
Georgi Denchev
Telerik team
commented on 30 Jan 2023, 08:13 AM

Hi, Aleksandr,

I am glad the problem has been resolved!

I'll add a note about updating the API example with additional information.

Best Regards,

Georgi

Tags
Form
Asked by
Aleksandr
Top achievements
Rank 1
Bronze
Bronze
Veteran
Answers by
Georgi Denchev
Telerik team
Share this question
or