1\ Tab page initialize
happen when user selects tab, but not when tab control initialized.
You need to implement
Extension.Tab.prototype.setParentControl = function Extension$setParentControl()
{
this.callBase("Tridion.Controls.DeckPage", "setParentControl", arguments);
var item = $display.getItem();
if (item)
{
this._updateTabState();
}
// if necessary
// $evt.addEventHandler(item, "load", this.getDelegate(this._updateTabState));
// $evt.addEventHandler(item, "loadfailed", this.getDelegate(this._updateTabState));
};
And _updateTabState
Extension.Tab.prototype._updateTabState = function Extension$_updateTabState(result)
{
var p = this.properties;
if (condition)
{
p.parentControl.showItem(this);
}
else
{
p.parentControl.hideItem(this);
}
};
2\ When item is saving, it fires validate
event before save, which you can handle. If your validation is ok, return true or nothing, otherwise – do return false
In initialize method:
$evt.addEventHandler(item, "validate", this.getDelegate(this.onItemValidate));
And
Extension.Tab.prototype.onItemValidate = function Extension$onItemValidate(event)
{
var c = this.properties.controls;
if (c.ExtraField.value.length == 0)
{
$messages.registerError("This field is empty", null, null, true);
return false;
}
};
UPD:
As a good practice I`d strongly suggest to avoid using hardcoded uris.
When you have a condition by which you define to show/hide tab, you can export this condition into item properties via DataExtender.
And then Use by ItemType extending get an access to this property.
In this case, updateState Condition would look like
if (Type.implementsInterface(item , "Extension.ItemType.Publication")) && item.isNewTabShouldBeShown())