AppSuite:Modifying forms by using extension points: Difference between revisions
From Open-Xchange
Line 36: | Line 36: | ||
<pre class="language-javascript"> | <pre class="language-javascript"> | ||
// disable | // disable the display_name field | ||
require('io.ox/core/extensions').point('io.ox/contacts/edit/personal').disable(' | require('io.ox/core/extensions').point('io.ox/contacts/edit/personal').disable('display_name'); | ||
// | // reenable the display_name field | ||
require('io.ox/core/extensions').point('io.ox/contacts/edit/personal').enable(' | require('io.ox/core/extensions').point('io.ox/contacts/edit/personal').enable('display_name'); | ||
</pre> | </pre> | ||
<pre class="language-javascript"> | <pre class="language-javascript"> | ||
// replace | // replace the display_name field by "Hallo World!" | ||
require('io.ox/core/extensions').point('io.ox/contacts/edit/personal').replace({ | require('io.ox/core/extensions').point('io.ox/contacts/edit/personal').replace({ | ||
id: " | id: "display_name", | ||
draw: function () { | draw: function () { | ||
this.append( | this.append( | ||
Line 56: | Line 56: | ||
<pre class="language-javascript"> | <pre class="language-javascript"> | ||
// modify the index to | // modify the index of the display_name field to bring it on top | ||
require('io.ox/core/extensions').point('io.ox/contacts/edit/personal').get(' | require('io.ox/core/extensions').point('io.ox/contacts/edit/personal').get('display_name', function (extension) { | ||
extension.index = | extension.index = 100; | ||
}); | }); | ||
</pre> | </pre> | ||
<pre class="language-javascript"> | <pre class="language-javascript"> | ||
// modify the hidden status to hide | // modify the hidden status to hide the display_name field | ||
require('io.ox/core/extensions').point('io.ox/contacts/edit/personal').get(' | require('io.ox/core/extensions').point('io.ox/contacts/edit/personal').get('display_name', function (extension) { | ||
extension.hidden = true; | extension.hidden = true; | ||
}); | }); |
Revision as of 12:26, 11 April 2013
Summary: This articles covers how to apply different changes to the contact form via modifying its extensionpoints and extensions.
Show available extensionpoints
The edit contact form of the contacts app is constructed by a set of extensionpoints. Each extensionpoint controls a single aspect of the contact.
To apply modifications the id of the point and the extension is needed.
For a quick overview of the available extensionpoints and extensions you can use the browser console.
// show all available extensionpoints require('io.ox/core/extensions').keys();
// you can filter down the list by using regular expression _(require('io.ox/core/extensions').keys()).filter(function (point) { if (/io.ox\/contacts\/edit/.test(point)) { return point; } });
// show all available extensions of a known extensionpoint require('io.ox/core/extensions').point('io.ox/contacts/edit/personal').all();
Modify extensionpoints
As described in Hands-on_introduction extensionpoints can be modified in multiple aspects.
// disable the display_name field require('io.ox/core/extensions').point('io.ox/contacts/edit/personal').disable('display_name'); // reenable the display_name field require('io.ox/core/extensions').point('io.ox/contacts/edit/personal').enable('display_name');
// replace the display_name field by "Hallo World!" require('io.ox/core/extensions').point('io.ox/contacts/edit/personal').replace({ id: "display_name", draw: function () { this.append( $("<div>").addClass("title").text("Hello World!") ); } });
// modify the index of the display_name field to bring it on top require('io.ox/core/extensions').point('io.ox/contacts/edit/personal').get('display_name', function (extension) { extension.index = 100; });
// modify the hidden status to hide the display_name field require('io.ox/core/extensions').point('io.ox/contacts/edit/personal').get('display_name', function (extension) { extension.hidden = true; });
Extend the validation via extensionpoint
In addition to the default validation another validationstep can be implemented by extending the proper extensionpoint.
// extend the validation require('io.ox/core/extensions').point('io.ox/contacts/model/validation/first_name').extend({ id: 'check_for_klaus', validate: function (value) { if (value !== 'Klaus') { return 'First name can only be Klaus'; } } });