how to remove fields from form class and view - zend-form

Depending on from where the form is called I want to remove some unused fields.
I tried the following from my controller class:
switch ($typ){
case 3: //Analyse
$form->get('analyseid')->setValue($id); //works
$form->remove('vertragid'); //doesn't work
break;
}
I get some errors:
No element by the name of [vertragid] found in form
\wiedervorlage\add.phtml(25): Zend\Form\Fieldset->get('vertragid')
Of course I try to get attributes in my view.phtml skript.
My question is: How can I remove a field from the form and the view, too.

Althought I'm not really a fan of this kind of workarounds, the solution here is quite simple.
If you need to remove certains elements given on some condition, you can remove them from the controller with the following lines:
switch ($typ) {
case 3:
// Remove the element 'vertragid'
$form->remove('vertragid');
// Remove inputfilters. This is necessary, because if the element
// is required, the inputfilter will always block the validation
// of the form
$form->getInputFilter()->remove('vertragid');
break;
}
To avoid errors in your view, you have to check if that element exists in the form:
if ($form->has('vertragid')){
echo $this->formRow($form->get('vertragid');
}

Related

Add Dynamic Behavior on Component in QML

Recently I wanna add behavior in js function in QML but I dont know how!
For example , how I can do this:
Behavior on color{
id:behavior
enabled:false;
ColorAnimation {}
}
Rectangle{
id:rect
Component.onCompleted: rect.setBehavior = behavior; // it's wrong expression
}
I just need some API like top wrong expression , is that exist?
also I tried bottom code too but couldn't work:
also I can try below code too :
Component.onCompleted: behavior.enabled = true;
because I want prevent working behavior when creating rectangle and enable it after completed , but it won't work correctly!
but when I have a lot of behaviors on specific conditions I just want use one line code for change behavior on (for example) Color , something like:
Component.setNewBehaviorOnColor(specificBehaviorOnColorID);

Binding list to a HTML textbox is not updating the view

In Aurelia, I have a textbox like this:
<input type="text" value.bind="contact.topics|commaList">
Where commaList is a value converter:
export class CommaListValueConverter {
toView(value) {
return value.join('|')
}
fromView(value) {
return value.split('|')
}
}
There are two things:
Updating the list (contact.topics) from code doesn't change anything in the view. Tried forcing two-way as well. The toView() is not called (tried to log calls). For comparison, in my view there is also a regular repeat topic of contact.topics which update fine.
Aurelia modifies my contact.topics list by adding an element __array_observer__: ModifyArrayObserver to my list. So now I somehow have to clean my list of such unwanted elements before saving (or dirty checking).
I update the array this way:
this.contact.topics.push('test')
The contents of the array display correctly in the for of loop (not shown).
gist
https://gist.run/?id=dd11c5837b77b29b586d2c4f978a7a48
Aurelia bindings don't react on Array and Object internal changes unfortunately.
You can't escape the __ private properties that aurelia adds for observation but since you are dirty checking an array you can take a clean clone of it with arr.slice()

how to hide dojo validation error tooltip?

I'm using dojo to validate input fields and if there is an error (for eg: required field) it appears in the dojo tooltip. But, I would like to show error in the custom div instead of tooltip.
So, I'm wondering if there is a way to hide/disable the validate error to appear in the tooltip? If so, I can capture the error message shown in the hidden tooltip and show the result in custom div, which will be consistent with error styling across the application.
Please advise. Thanks.
I would recommend to use the standard Dojo validation mechanism, contrary to what vivek_nk suggests. This mechanism works great in most cases, and covers most situations (required, regular expressions, numbers, dates etc.).
To solve your issue: you can overrule the "dispayMessage" function of a ValidationTextBox (for example).
displayMessage: function(/*String*/ message){
// summary:
// Overridable method to display validation errors/hints.
// By default uses a tooltip.
// tags:
// extension
if(message && this.focused){
Tooltip.show(message, this.domNode, this.tooltipPosition, !this.isLeftToRight());
}else{
Tooltip.hide(this.domNode);
}
}
Just create your own ValidationTextBox widget, extend dijit/form/ValidationTextBox, and implement your own "displayMessage" function.
Simple solution for this scenario is not to add the "required" condition at all to those fields. Instead add a separate event handler or function to check for this validation.
For eg: add a function for onBlur event. Check if the field is a mandatory. If so, show message in the custom div as expected.
<input data-dojo-type="dijit/form/TextBox"
id="sampleText" type="text" mandatory="true" onBlur="checkMandatory(this)"/>
function checkMandatory(field) {
if(field.mandatory=='true' && field.value=="") {
alert('value required'); // replace this code with my showing msg in div
} else {
field.domNode.blur();
}
}
This above code snippet does not use Dojo for validation, rather manual. Dojo actually helps to ease this by just adding the attribute "required". If that is not required, then just ignore Dojos help for this case and go native.
So, for all fields, just add the attributes - "mandatory" & "onBlur", and add the above given function for onBlur action for all these fields.

How to Mimic Finder NSPredicateEditor leftExpression list

I would like to mimic the Finder's predicatesList. Especially the LeftExpressions popup with its "other" (in German: "Andere...") menu entry and like to popup a NSSheet with a user selectable list of search predicates.
My approach was to create some NSPredicateEditorRowTemplates and one last custom rowTemplate with a leftExpression named "other...".
Then I override the templateViews method and added a separatorItem:
-(NSArray *)templateViews{
NSMutableArray * views = [[super templateViews] mutableCopy];
// I tried already to add here my custom menu entry, but if I add more templates my custom entry (and the separator line) is not fixed at the last index.
if (!isCustomMenuItemAdded) {
NSPopUpButton *leftButton = views[0];
// Add a menu separator
[[leftButton menu]insertItem:[NSMenuItem separatorItem] atIndex:[leftButton menu].itemArray.count-1];
}
return views;
}
My custom predicateEditor is now shown correctly, But if I click on the last menu item 'Other.." the dummy NSPredicateRowTemplate shows up.
I tried to override the -(id)copy method in my rowTemplate class to suppress the new line but that feels strange to me.
-(id)copy{
return nil; // OK, now there is no new row, but this throws an internal exception
}
My question is:
Is there a better way to add a custom menu entry in the left expressions popupButton?
and
How can I suppress that a new predicateTemplateRow is shown in the PredicateEditor?

DojoX Mobile ListItem load HTML via AJAX and then remove from DOM

Let's say in a view I have a DojoX Mobile ListItem that is pulling an HTML view fragment into the DOM via AJAX and then transitioning to that view. Assume this is all working fine.
Now, I go back to the initial view that had that ListItem on it and click some other button that destroys that view node from the DOM. If I now click on that ListItem that previously loaded that view node into the DOM (which has now been removed), it will try to transition to a view that doesn't exist. It doesn't know that it has been removed.
Is there some type of way to tell a ListItem that it needs to fetch the HTML again because what was previously fetched no longer exists? I am not seeing anything about doing this in any documentation anywhere. I don't think a code sample is really necessary here, but I can provide a minimal one if necessary.
I went a different route and left the view exist in the DOM, and simply made a function that clears all sensitive data out of the view.
Okay, in this case, i guess you could hook the onShow function of your ListItem container(or any other onchange event). Create a listener for said handle to evaluate if your item needs reloading. Following is under the assumtion that it is the item.onclick contents showing - and not the label of your item which contains these informations
Or better yet, do all this during initialization so that your ListItem container will be an extended with custom onClick code.
Seems simple but may introduce some quirks, where/when/if you programatically change to this item, however here goes:
function checkItem() {
// figure out if DOM is present and if it should be
if( isLoggedIn() ) {
this.getChildren().forEach(function(listitem) {
if( dojo.query("#ID_TO_LOOK_FOR", listitem.domNode).length == 0 ) {
// this references the listItem, refresh contents.
// Note: this expects the listitem to be stateful, have no testing environment at time being but it should be
listitem.set("url", listitem.url);
}
});
}
}
Preferably, set this in your construct of the container for your ListItems
var listItemParent = new dojox.mobile.RoundRectList({
onShow : checkItem,
...
});
Or create listener
var listItemParent = dijit.byId('itemRegistryId');
// override onClick - calling inheritance chain once done
dojo.connect(listItemParent, "onClick", listItemParent, checkItem);