AngularJS - Building a dynamic form based on a json - json

I am using the AngularDynamicform to generate a dynamic form in page and the fields are displaying fine in a horizontal manner. But I want to display the input fields with in different sections in the page.
In my page
<div class="box-content">
<h4 class="page-header">New Contact</h4>
<dynamic-table-form fields="fields" data="data" class="form-horizontal">
<input dynamic-field-type="string" ng-model="value" type="text" maxlength="{{config.maxLength}}" size="{{config.maxLength}}">
<input dynamic-field-type="date" ng-model="value" type="date">
<ul dynamic-field-type="array">
<li dynamic-field-child>
<ng-transclude></ng-transclude>
<button ng-click="removeChild(childKey)">Remove</button>
</li>
<button ng-click="addChild()">Add Another</button>
</ul>
<select dynamic-field-type="select" ng-model="value" ng-options="option.value as option.caption for option in config.options"></select>
<input dynamic-field-type="integer" ng-model="value" type="number" size="{{config.maxLength}}" maxlength="{{config.maxLength}}" min="{{config.minValue}}" max="{{config.maxValue}}">
<button ng-click="create()">Save</button>
</dynamic-table-form>
<button ng-click="create()">save</button>
And in my controller
$scope.fields = [
{
caption: 'Name',
model: 'name',
type: 'string',
maxLength: 25
},
{
caption: 'Date of Birth',
model: 'dateOfBirth',
type: 'date'
},
{
caption: 'Employee name',
model: 'employee.name',
type: 'string',
maxLength: 25
},
{
caption: 'Employee City',
model: 'employee.city',
type: 'string',
maxLength: 25
}
];
for example, I want to display the last two fields(Employee name & Employee City)in other section called Employee details. How can I do it?
Thanks in advance.

Related

VueJS Vuelidate and deep nested Array/objects

hope someone can help me I'm working on this since 2 days. I have the following Data in my component:
var types = [
{
**required**: true,
agreements: [
{ selected: true, desc: 'red' },
{ selected: false, desc: 'green'}
]
},
{
required: false,
agreements: [
{ selected: false, desc: 'red' },
{ selected: false, desc: 'green'}
]
},
];
I want to validate all the checkboxes (they have v-model on this selected attributes here!), to be checked, if the parent value required (see my data required!) is true. My Validations looks like this but I miss a last little bit of help to get this required value into my validator selected requiredIf function.
validations: {
types: {
$each: {
agreements: {
$each: {
selected: {
requiredIf: (value) => value === value.parent.required
}
}
}
}
}
}
Hope you understand me right. My Template looks like this:
<div class="mb-3" v-for="type in agreementTypes" :key="type.id">
<h3 class="text-primary">{{ type.displayName }}</h3>
<ul class="list-unstyled">
<li v-for="agreement in type.agreements" :key="agreement.id">
<p>{{ agreement.description }}</p>
<div class="mb-3 form-check form-switch">
<input
class="form-check-input"
type="checkbox"
role="switch"
:checked="agreement.active"
:id="agreement.id"
:required="agreement.required"
v-model="agreement.selected"
/>
<label class="form-check-label" for="agreements">{{ agreement.label }}<span v-if="agreement.required">**</span></label>
</div>
</li>
</ul>
</div>
Any Help will be apreshiated!
bye,
Marcel

Manual rendering failed

Manually rendering the page, but it didn't work as I thought
#html
<input class="" for="{{art_form.title}}" required>
#form.py
class ArticleForm(forms.ModelForm):
class Meta:
model = Article
fields = ['title', 'body', 'subject']
#google Elements;Actual output code
<input class="" for="<input type="text" name="title" value="这是一篇测试文章111" maxlength="255" required id="id_title">" required>
ok,render the form through 'form. Py' to achieve the effect.
Or add class and ID to let the front end render.
#form.py
class ArticleForm(forms.ModelForm):
class Meta:
model = Article
fields = ['title', 'body', 'subject']
error_messages = {
'title': {
'required': _('请输入标题'),
'max_length': _('标题最多50个字'),
'min_length': _('内容太少,请重新填写'),
},
'body': {
'required': _('请输入内容'),
'min_length': _('内容太少,请重新填写'),
}
}
widgets = {
#字段样式
'title': forms.TextInput(
attrs={'class': 'form-control',
'placeholder': '请输入标题(最多50个字)'})
}

Order select option with key value by key

i'm trying to order alphabetically my list by the key and i'm having problems with that.
i tried to add " | orderBy 'key'" BUT IT DIDIN'T WORK, ANY SUGGESTION?
my html:
<label for="select-aspects" class="col-lg-1 col-md-1 col-sm-1 control-label">UMS:</label>
<div class="col-lg-5 col-md-5 col-sm-5">
<select data-smart-select2
multiple
data-ng-options="key as key for (key, value) in vm.umsAspects "
data-ng-disabled="!vm.currentProduct.adoptedListings[vm.currentListingPosition].agentDecisionContract.action || vm.currentProduct.adoptedListings[vm.currentListingPosition].agentDecisionContract.reason!='Aspects'"
ng-required="vm.currentProduct.adoptedListings[vm.currentListingPosition].agentDecisionContract.reason=='Aspects'"
style="width: 100%;"
ng-model="vm.currentProduct.adoptedListings[vm.currentListingPosition].agentDecisionContract.reasonAspects"
class="select2"
id="select-aspects">
</select>
</div>
my list looks like this:
{ Brand: {umsValues: Array(543), multiValue: true, aspectRequired:
true}, UPC: {umsValues: Array(543), multiValue: true, aspectRequired:
true} Model: {umsValues: Array(543), multiValue: true, aspectRequired:
true}, Type: {umsValues: Array(543), multiValue: true, aspectRequired:
true} }
in this case i want to display it in the following order:
Brand
Model
Type
UPC

How to get form value of <ul> in golang?

In my use case I am using tag tag-it to get tags from user. I am getting the tags input in html <ul> form. I am using golang in server side.
html:
<form class="comment-form" action="/add/" method="POST" enctype="multipart/form-data">
<div class="form-input">
<label for="tags_label">Tags</label>
<ul id="tags">
<script type="text/javascript">
$("#myTags").tagit();
var tagsArray = ["C", "C++", "Go", "Ruby"];
$("#tags").tagit({
itemName: "teamId",
fieldName: "teamName",
availableTags: tagsArray,
allowSpaces:true,
caseSensitive:false,
removeConfirmation:true,
placeholderText:"Tags",
tagLimit: 5,
allowDuplicates: false,
singleFieldDelimiter: ',',
onlyAvailableTags: false
});
</script>
</ul>
</div>
</form>
and in server end I am trying to get the value like below similar to other fields in the form,
tags := r.FormValue("tags")
log.Printf("Tags : ", tags)
But it is not working. Could someone help me with this?
EDIT:
When I inspect the element this is what I see,
<div class="form-input">
<label for="tags_label">Tags</label>
<ul id="tags" class="tagit ui-widget ui-widget-content ui-corner-all">
<script type="text/javascript">
$("#myTags").tagit();
var tagsArray = ["C", "C++", "Go", "Ruby"];
$("#tags").tagit({
itemName: "teamId",
fieldName: "teamName",
availableTags: tagsArray,
allowSpaces:true,
caseSensitive:false,
removeConfirmation:true,
placeholderText:"Tags",
tagLimit: 5,
allowDuplicates: false,
singleFieldDelimiter: ',',
onlyAvailableTags: false
});
</script><li class="tagit-new"><input type="text" class="ui-widget-content ui-autocomplete-input" placeholder="Tags" autocomplete="off" role="textbox" aria-autocomplete="list" aria-haspopup="true"></li>
</ul>
</div>
Found the problem: you expected a single field but you didn't specify it in the options of tag-it. Use it as following (added some comments for clarity):
<script type="text/javascript">
$("#myTags").tagit();
var tagsArray = ["C", "C++", "Go", "Ruby"];
$("#tags").tagit({
fieldName: "teamName", // The name of the hidden input field
availableTags: tagsArray,
allowSpaces:true,
caseSensitive:false,
removeConfirmation:true,
placeholderText:"Tags",
tagLimit: 5,
allowDuplicates: false,
singleField: true, // Use a hidden input element with the fieldName name
singleFieldDelimiter: ',', // Optional, default value is same.
onlyAvailableTags: false
});
</script>
During runtime (and entering tags) a hidden <input> will be used, with the tag that you specified in the tag-it options.
<input type="hidden" style="display:none;" value="Go,another value,C" name="teamName">
In Go, handle it as following (you missed the %s in Printf):
tags := r.FormValue("teamName")
log.Printf("Tags: %s", tags)
You can then split the tags with strings.Split.

Bootstrap multiselect dropdown does not work inside div having ng-repeat

I want to use bootstrap multiselect dropdown for selecting multiple values for parameters . I am using it like -
<div ng-repeat="param in parameters">
<div>{{param.name }} :</div>
<div ng-show = "param.multipleValues">
<select ng-model="param.value" id="testMultiSelect" multiple="multiple">
<option ng-repeat="v in values" value="{{v}}" >{{v}}</option>
</select>
</div>
<div ng-show = "!param.multipleValues">
<input type="text" ng-model="param.value">
</div>
</div>
But , somehow , multiselect is not working inside ng-repeat. If I put it outside of this div having ng-repeat , it works.
It comes like in image -
This may helps you
var app = angular.module('testApp', [ ]);
app.directive('telDropdownmutiple', ['$http', function ($http) {
return {
restrict: 'E',
scope: {
array: '=',
validate: '#',
ngModel: '=',
title: '#',
checkId: '#',
ngmaxLength: '#',
ngminLength: '#',
lblvalue: '#',
textboxSize: '#',
lblSize: '#',
ngShow: '#',
textboxtype: '#',
getString: '#',
multiple: '#',
},
template:'<div id="{{ checkId }}" > <span>{{ title }}</span>:<select {{ multiple }} class="{{className}}" ng-model="ngModel" ng-options="a[optValue] as a[optDescription] for a in array" requireiftrue="{{ validate }}"></div>'+
'<option style="display: none" value="">{{title}}</option>' +
'</select> </div>',
link: function (scope, element, attrs) {
scope.lblvalue = attrs.lblvalue;
scope.title = attrs.title;
scope.optValue = attrs.optValue;
scope.optDescription = attrs.optDescription;
}
};
}]);
app.controller('testController', ['$scope', '$location', function ($scope, $location) {
$scope.SelectMultiple = [
{Id: 1, Description: "option1"},
{Id: 2, Description: "option2"},
{Id: 3, Description: "option3"},
{Id: 4, Description: "option4"},
{Id: 5, Description: "option5"},
{Id: 6, Description: "option6"},
{Id: 7, Description: "option7"},
{Id: 8, Description: "option8"},
{Id: 9, Description: "option9"},
{Id: 10, Description: "option10"}
];
}]);
<script data-require="angular.js#~1.3.15" data-semver="1.3.15" src="https://code.angularjs.org/1.3.15/angular.js"></script>
<body class="hold-transition skin-blue sidebar-mini" data-ng-app="testApp">
<!-- Logo -->
<!-- Left side column. contains the logo and sidebar -->
<div class="content-wrapper" style=" margin-top: 50px; margin-bottom: 10px; height: 350px; overflow-y: auto; " ng-controller="testController">
<tel-Dropdownmutiple multiple ng-model="registration.multipledropGender" lblvalue="Gender" array="SelectMultiple" opt-value="Id" opt-description="Description" validate='true' class-Name="form-controlselect select2" ></tel-Dropdownmutiple>
</div>
</body>