How do I replace an attribute value for attribute with multiple values in Wicket? - wicket

My class attribute has two CSS class values. The HTML starts out like this:
<input type="button" wicket:id="rowButton" class="jelly-button greenGradient"/>
And I want to dynamically change it to this:
<input type="button" wicket:id="rowButton" class="jelly-button redGradient"/>
Currently I am doing this:
component.add(new SimpleAttributeModifier("class", "jelly-button redGradient"));
What is the best way to do this in Wicket? There must be a more 'proper' way to do this than what I have done above.

Instead of using an attribute modifier with fixed text you could use an attribute appender with the text retrieved from a model. To change the class, just change the model's value. For example:
Model<String> gradientModel = new Model<String>("greenGradient");
...
component.add(AttributeModifier.append("class", gradientModel));
in the markup just have
<input type="button" wicket:id="rowButton" class="jelly-button"/>
Then when it is time to change the gradient use
gradientModel.setObject("redGradient");
or
gradientModel.setObject("greenGradient");

The example in the javadoc below explains it well
http://www.jarvana.com/jarvana/view/org/apache/wicket/wicket-core/1.5.2/wicket-core-1.5.2-javadoc.jar!/org/apache/wicket/behavior/AttributeAppender.html

Related

angularjs2: setting fields to "dirty", especially datepicker

I am new to Angular2/Typescript, since I come from the Java world, I decided to learn Typescript and Angular2 directly.
I want to leave most of the logic on the server, thus I don't need complex validation management on the client. So all I want is the user to fill out forms, and post/put all the fields to the REST Service.The goal is to leave the client side as light as possible.
I have a form:
<form role="form" (ngSubmit)="onSubmit()" #ArbeitstagForm="ngForm">
and a field in it, some datepickers too: similar like this:
<input type="text" class="form-control pull-right" id="datepicker" [(ngModel)]="model.datum">
When I submit the form, I call this function:
model = new Arbeitstag();
onSubmit(form:any) {
alert(JSON.stringify(this.model));return false;
}
So that alerts me the the entered data as JSON, which I will after send to a REST Service. It works actually great, BUT only when I actually type something into the field, when I have a default value, or I set the field with a datepicker, the model object values will remain empty.
I've found out about the dirty setting of the fields, which are false by default and are getting true when I type something in and that's also what I see when I check firebug, but that's definitely not what I want to achieve.
Is there a way to set all the fields dirty in a form in Angular2? I've found many examples for Angular.js 1, but not for Angular2/Typescript.
Control has a markAsDirty() (and markAsTouched()) method
<input #datePicker="ngForm" type="text" class="form-control pull-right" id="datepicker" [(ngModel)]="model.datum">
<button (click)="datePicker.control.markAsDirty()">update dirty status</button>
Plunker example
What I usually do is get a reference to the form in my component, using ViewChild. With that reference I can mark to form dirty or touched when I need to. Like so:
export class MyComponent implements OnInit, OnDestroy {
#ViewChild('form') form: NgForm;
...
public methodWithFormChange(): void {
this.form.control.markAsDirty();
}
}
;-)

Unable to keep the static data for the input type fields in angular material

How to make a default static value for input in material design?
<input type="text" value="xyz" />
but in material design angular I am unable to keep the static value like value="xyz
<md-input-container>
<label>Start date</label>
<input ng-model="agg.startDate" value="xyz">
</md-input-container>"
value xyz is not affected in this case.
In your controller create a variable named agg.startDate using the $scope variable, like following code to set the value of input field
$scope.agg = {startDate: 'xyz'};
check this fiddle link

How to get the filename of a filepicker.io picture to appear in the input field next to it

I am trying to get the filename of an uploaded picture to appear in the input field next to the picker button (for filepicker.io) . Basically I am trying to find what to put in the value field for the input tag to get the filename to appear once the picture is uploaded. Here is the code I have:
<div class="row margin" id='img-row'>
<input id="filename" disabled="disabled" value="<WHAT DO I PUT HERE?>" class="input" type="text" style="width: 360px;"/>
<input name="img" data-fp-class="form-simple-action-btn filepicker_launcher" data-fp-button-text="Choose Image" data-fp-services="COMPUTER,FACEBOOK,FLICKR,INSTAGRAM,PICASA" data-fp-container="modal" data-fp-mimetypes="image/*" type="filepicker" data-fp-apikey="#################" id='campaign-img-input' value="<php echo h($_POST['img'])"/>
</div>
Thank you for your help! I haven't found any other examples like this in the documentation.
The recommended way to do this would be to bind a function to the onchange event of the filepicker input type. Once the upload occurs, the function will be called, and you can pull the filename out of the e.fpfile attribute.
Alternatively, it may be easier to use the filepicker.pick call directly given that you are interested in customizing the behavior. The widget is great for a drop-in solution in many cases, but if you're looking to customize further I'd recommend using the javascript api directly.

Using negative value in Zend Form Element Radio causing html errors

$score = new Zend_Form_Element_Radio('score');
$score->setRequired(true)
->setSeparator('')
->setMultiOptions(array(1 =>'Positive', -1 =>'Negative'))
->setDecorators(array('ViewHelper'));
Renders as
<label for="score-1">
<input name="score" id="score-1" value="1" checked="checked" type="radio">Positive
</label>
<label for="score-1">
<input name="score" id="score-1" value="-1" type="radio">Negative
</label>
Is the fact that it's using the same ID for the inputs and labels normal behavior or a bug?
How can I correct this?
I can't change the values as technically they are required to be that way
The real problem this causes is that when you click the negative the positive gets selected instead!
Thanks
Looks like the standard ViewHelper decorator for a radio control uses a FormRadio view-helper. When this view helper creates the id it uses on the <input> element and the <label> element, it first applies the standard AlNum filter, which is filtering out your minus sign.
So, it looks to me that instead of using the standard ViewRenderer decorator, you will have to create a custom decorator that calls your own custom FormRadio view helper.
You might be able to avoid creating your own decorators and view helpers by creating your own custom AlNum filter that allows those minus signs. The trick is to set that path only for this single use so that you;ll be able to use the normal Alnum filter for other elements.
Alternatively, you could probably trick the ViewHelper into using a custom FormRadio helper by adding a helper path on the view object so that it loads your custom view helper instead of the standard one.
Just some ideas.

How to dynamically populate a choices widget in symfony?

Suppose there is an image_url column in database.
I want the user to choose from several recommended images,which is something like this:
<input type="radio" value="domain.com/path_to_img1" name="image_url" />
<img src="domain.com/path_to_img1" />
<input type="radio" value="domain.com/path_to_img2" name="image_url" />
<img src="domain.com/path_to_img2" />
Where the image urls are generated on the fly.
How to do this in a symfony flavor by sfForm?
I tried this:
$form->widgetSchema['key'] = new sfWidgetFormSelect(...)
But get a fatal error:
Cannot access protected property
But what's the exact way to do this?
Well, standart approach is to write a widget.
In your concrete case it seems you actually want to perform a choice, right? So you have to implement another sfWidgetFormChoice renderer. To do that, inherit sfWidgetFormSelectRadio (let's call them sfWidgetFormSelectRadioImage) to learn them to render labels as <img> tags. Then ask sfWidgetFormChoice explicitly to render itself with sfWidgetFormSelectRadioImage class, and that should be all.
In your form configuration insert the following:
$this->widgetSchema['choices'] = new sfWidgetFormChoice (array('choices' => $custom_values_array));