How to populate camunda html form Select from Json - camunda

I am trying to populate camunda html form select from json sent from my external service client.
Here is my sent json -
{myData=[{"id":1,"name":"This is one","value":"value11","localName":"this is local name 11"},{"id":2,"name":"This is Two","value":"value22","localName":"this is local name 22"}]}
Here is my html form -
<form>
<div>
<select
cam-variable-type="String"
cam-variable-name="selected_option"
ng-options="item as item.name for item in myData track by item.id"
ng-model="selected"
class="form-control">
</select>
</div>
<script cam-script type="text/form-script">
camForm.on('form-loaded', function() {
// tell the form SDK to fetch the variable named 'myData'
camForm.variableManager.fetchVariable('myData');
});
camForm.on('variables-fetched', function() {
// work with the variable (bind it to the current AngularJS $scope)
$scope.myData = camForm.variableManager.variableValue('myData');
});
</script>
</form>
But it is coming up like below as undefined -
And i can see my json myData in next step and it's values -
Any help on how to populate my html form select from my json myData
Thanks

You should parse your process variable, because it has String type
$scope.myData = JSON.parse(camForm.variableManager.variableValue('myData'));
Without parsing your select ng-options ran through every letter in your string, that's why you had so many options in select instead of two. Also you didn't set correct id for ng-options. It must be like this:
ng-options="item.id as item.name for item in myData track by item.id"

Related

Django form submission without reloading page

I have a django register form .On the event of an invalid form submission, page is reloading.I need to stay on that same page if the data entered is invalid.
Is there any way to get this done without ajax ?
If not, how to do this with ajax
Well if you want to validate the data before submitting then you can just use plain javascript to validate the values and update your html displaying output as shown below.
Consider this below form.
<form>
<input id="target" type="text" value="">
</form>
<div id="other">
Trigger the handler
</div>
Use below script
<script>
$("#target").keyup(function () {
console.log(this.value);
});
</script>
In above script once you get the value you can write the logic to valid the same and update you result in html accordingly.
NOTE: Main point here is the event handler as you type anything it calls the function.
Obviously this may not be the best way to achieve this but consider this as demonstration.

How to preselect an option in an embedded HTML form?

I try to preselect an option of a select in an embedded HTML form in Camunda Tasklist, but always the first option is preselected.
I followed Binding to a Process Variable:
Binding to a Process Variable
A select box can be bound to a process variable using the cam-variable-name directive:
<select cam-variable-name="foo" cam-variable-type="String">
<option>bar</option>
<option>zar</option>
</select>
Research
I read also CAM-3173:
select box doesn't show the correct option
If I set the value of variable by a select box on the start form, the next task form didn't show the option that has been choosen in the start form. It uses the same select box.
but I use Camunda 7.9 and the problem is fixed since version 7.2.3.
HTML
<form>
<select cam-variable-name="variable" cam-variable-type="String">
<option value="option1">option1</option>
<option value="option2">option2</option>
</select>
</form>
Result
option1 is preselected. I checked the process variable before entering the user task and it contains option2.
What did I wrong? If the bug still exists, is there any work-around?
I found a work-around, see Camunda Reference:
Implementing Custom Fields
The following is a small usage example which combines some of the features explained so far. It uses custom JavaScript to implement a custom interaction with a form field which does not use any cam-variable-* directives.
It shows how custom scripting can be used for
declaring a variable to be fetched from the backend,
writing the variable’s value to a form field,
reading the value upon submit.
[...]
The above example uses jQuery for interacting with the HTML controls. If you use AngularJS, you can also populate the $scope in the variables-fetched callback and read the values from the $scope in the submit callback:
My changed HTML:
<form>
<script cam-script type="text/form-script">
camForm.on('form-loaded', function() {
camForm.variableManager.fetchVariable('variable');
});
camForm.on('variables-fetched', function() {
$scope.variable = camForm.variableManager.variable('variable');
});
camForm.on('submit', function() {
camForm.variableManager.variableValue('variable', $scope.variable);
});
</script>
<select data-ng-model="variable">
<option value="option1">option1</option>
<option value="option2">option2</option>
</select>
</form>

In Django how to getbinary field data from POST form

I have one HTML file, where I am using one image upload button. Now this image is stored in the MySql database as Blob. I need to get or read this image data somehow in Django through post method. Can anyone please help how to do?
Icon is defined like :
icon = models.BinaryField(null=True)
My Html:
<input type="file" id="toolicon" accept="image/*" data-type='image' >
<button id="OpenImgUpload" style="margin-left: 100px">Image Upload</button>
In JQuery:
$('#OpenImgUpload').click(function(){ $('#toolicon').trigger('click'); });
Image:
Now I want to get this file as Binary Field data. Till now I have used :
tool_icon = request.POST('toolicon', '')
tool_icon = request.POST.get('toolicon', '')
tool_icon = base64.b64encode('toolicon', '')
Nothing works ... Can any one please help me.
Uploaded files are contained in request.FILES with the key corresponding to the name attribute on the input element.
So you should add a name attribute to your input:
<input type="file" name="toolicon" ...
And then access the data using request.FILES:
tool_icon = request.FILES.get('toolicon', '')
The request must have a content type of multipart/form-data which you should set on your form:
<form enctype="multipart/form-data" ...

twitter bootstrap date picker not working

I have been extensively searching for the answer but i cant seem to find one that works. I am using Django 1.4, with twitter boostrap 2.0.4 and i am trying to use date picker (eyecon) with no success. When i click on the input box no date box shows up.
<div id="due_date">
<input type="text" value="02/16/12" data-date-format="mm/dd/yy" id="datepicker" >
</div>
At the end of my base.html i have (right before closing the body):
<script src="/site_media/js/jquery.script.js"></script>
<script src="/site_media/js/bootstrap-datepicker.js"></script>
Finally on me jquery.script.js i have:
$(document).ready(function(){ $('.datepicker').datepicker()});
You have selected all elements who have the class "datepicker", while your input element definition does not have such a class but rather has datepicker as id attribute set.
Either select the id field $("#datepicker") or add a class ".datepicker" to your input field.
Do this: $(document).ready(function(){ $('#datepicker').datepicker()});
As you have set id="datepicker"
'.' is used for class and '#' is used for id

APEX 3.2: Embed HTML Region into HTML Region

I found the following javascript example for uploading multiple files in one session:
Upload multiple files with a single file element
My question is that in my APEX 3.2 page, I currently have a region that looks like this:
And I want to take out the default 'File Browse' and put in the multiple file upload portion in it's place.
Is there a way to put a region within a region? If not, how can I add an HTML item within a region?
Here is the code that I have in the second screen shot (html region):
<form enctype="multipart/form-data" action="your_script_here.script" method = "post">
<input id="my_file_element" type="file" name="file_1" >
<input type="submit">
Files:
<div id="files_list"></div>
<script>
var multi_selector = new MultiSelector( document.getElementById( 'files_list' ), 3 );
multi_selector.addElement( document.getElementById( 'my_file_element' ) );
</script>
</form>
You can create a "Display as Text" item and set your HTML code as the source. Make sure that the item is not set to escape HTML, otherwise you will just see the HTML and not the controls.
The result comes out like this (I have a text item "Request Title" followed by the display item based on your HTML: