Few questions about global datatype

Topics: General
Nov 4, 2011 at 11:47 AM

I am learning about global datatypes now and I have a few questions:

1) Is it possible to add javascript or apply a xslt stylesheet to the form that you setup with the Form markup?  I mean the form used to enter content in the admin.

2) I would like to hide a field based on the selection of a boolean value of another field. How should I make that happen? Is this possible at all?

3) I would like to validate a field based on the value of another field. Is this possible? If so, how?

Thank you.

Nov 5, 2011 at 9:13 PM

The Composite.Forms.Renderer feature is not super flexible - it's based on ASP.NET User Controls (which render after the XSLT features in C1, so you can't use them) and have no features for cross field logic. It's great for easy and fast form creation, but if you need a more advanced form you probably better of building the form in another way.

If you are not keen on coding anything but html, take a look at Composite.Forms.FormSubmitHandler - this only stores submitted data in a flat xml file, but the customization work is limited to writing a html form. If you back-end (like xslt, c# or asp.net) read on.

If you want a pure html/javascript approach, then make your data type's AddDataInstance function (or an XSLT stub you create) public so you can execute it via a URL. When the user submits the form, have your script code do validation and then "AJAX call" the publiched functions URL and send the field value as post or get.

The Forms Renderer feature can be tweaked if you are into asp.net; you can add custom xslt logic via code, you can modify the html/script of existing asp.net controls by editing .ascx files below ~/Frontend/Composite/Forms/Renderer and you can introduce new controls that can render fields in a special way (like a textbox which toggle based on a checkbox). I doubt any of this will be a convinient way to achieve your goal though.

You can also write the form in html/script and write server side validation/insert logic. You can put validation logic in script and/or C1 Functions (XSLT or C#), depends if validation is critical or you expect non-js clients. Storing data can be done by a custom C1 Function as well. With C# you can use the C1 Data API, and with XSLT you can emit C1 Function markup that inserts data (AddDataInstance) and data will be inserted. This give most control and validation, but it is also more time consuming than the html/javascript approaches.

Personally I'd take the "AJAX approach" if client side validation is enough. Perhaps wrap the AddDataInstance call in a custom XSLT if some server side sanity check is needed.

Nov 7, 2011 at 9:00 AM

In addition to this sollution:
If you want a pure html/javascript approach, then make your data type's AddDataInstance function (or an XSLT stub you create) public so you can execute it via a URL. When the user submits the form, have your script code do validation and then "AJAX call" the publiched functions URL and send the field value as post or get.

If the admin you have an option 'Add data' in the data type's menu that uses the form you create for the datatype. Is it possible to override that option and to make it use the 'Ajax form' instead? Or is it better to make a C1 Console application for that?

Nov 7, 2011 at 9:23 AM

The whole "Global Data" area where you define datatypes and add/edit/delete instances is just a C1 Console Application itself and you would find that it only works with truly dynamic types. If you defined types in code, they won't show up here.

I would create my own Tree Definition where you have full control over how the tree should be rendered, and add your own commands for adding and deleting data. For the Add-command you would open a normal .aspx which contains the ajax form and lets you add data that way.