Compare value in custom fields of multiple user picker - jira

I am new to groovy.
I'm trying to compare the value of two user multiple choice fields. as a result, if there is a match, display an error on the screen. for fields with one choice there are no problems. script
def fieldA = getFieldByName('User Picker A')
if(fieldA.value == fieldB.valuee
def fieldB = getFieldByName('User Picker B')
def currentField = getFieldById(fieldChanged)
fieldA.clearError()
fieldB.clearError()
{currentField.setError("Please select a different user. $currentField.value was already used.")}
for multiple selection I need to apply contains but I don't understand how to do it. stuck on it
// If the first option is selected in the multi select list then make the text field required.
if(selectVal1.contains("") ) {
currentField.setError( "Пожалуйста, выберите другого пользователя. Значение $currentField. уже было использовано." )
}`
Here thus I try to compare on matches of a field of a multiple choice of users. but i lack skills
SelectList1.getValue().each {
if(selectVal2.contains(selectVal1)) {
currentField.setError( "Пожалуйста, выберите другого пользователя. Значение $currentField. уже было использовано." )}
}
I will be grateful for any help

I hope someone will be useful. working code for comparing two given arrays, searching for matches and displaying an error
SelectList3.getValue().each {
if(selectVal3.contains("fokinanv") && (selectVal1.contains("fokinanv"))) {
currentField.setError( "Пожалуйста, выберите другого пользователя. Значение $currentField. уже было использовано." )}
if(selectVal3.contains("zverevaav1") && (selectVal1.contains("zverevaav1"))) {
currentField.setError( "Пожалуйста, выберите другого пользователя. Значение $currentField. уже было использовано." )}
и тд перебор условий

Related

Free Text Entry in Angular Material mdAutoComplete

I want my angular material autocomplete to be a list of suggestions but not requirements. However I'm not sure how to implement as their is no clear example from the Angular Material docs.
In the example below my model is $ctrl.item.category
Clearly the example below is wrong, as my model is linked to md-selected-item, but this only works if I select an item. I want the user to be able to free enter the text if the item is not in the list. Basically how autocomplete already works in most browsers.
I see plenty of questions on how to disable this, but they are not trying to disable so much as clean up the left over text when an item is not selected. In these cases when an item is not selected then the model value is null, but text is left in the input.
I want the text left int he input to be the model value if the person does not select (or a match is not made).
md-autocomplete(
md-floating-label="Category Name"
flex="50"
md-input-name="category"
md-selected-item="$ctrl.item.category"
md-search-text="catSearch"
md-items="category in $ctrl.categories"
md-item-text="category"
md-min-length="0"
md-select-on-match=""
md-match-case-insensitive=""
required=""
)
md-item-template
span(md-highlight-text="catSearch" md-highlight-flags="^i") {{category}}
My options ($ctrl.categories) is an array of strings ['Food','Liqour'] and I wan the user to be able to use one of those or free enter Tables as their choice.
In this case you should link md-search-text to your model.
If you want to implement fuzzy search you have to write the filter method yourself. Look at this example:
template:
<md-autocomplete
md-items="item in $ctrl.itemsFilter()"
md-item-text="item.label"
md-search-text="$ctrl.query"
md-selected-item="$ctrl.selected"
>
<md-item-template>
<span md-highlight-text="$ctrl.query">{{item.label}}</span>
</md-item-template>
<md-not-found>
No item matching "{{$ctrl.query}}" were found.
</md-not-found>
<div ng-messages="$ctrl.myValidator($ctrl.query)">
<div ng-message="short">Min 2 characters</div>
<div ng-message="required">Required value</div>
</div>
</md-autocomplete>
controller:
var items = [ ... ];
ctrl.itemsFilter = function itemsFilter() {
return ctrl.query ? filterMyItems(ctrl.query) : items;
};
ctrl.myValidator = function (value) {
return {
short: value && value.length < 2,
required : value && value.length < 1,
};
};
then you just need to add filterMyItems method to filter your items
To improve the answer of #masitko, I have implemented the filter in a way, that it adds the query to the filtered list. So it becomes selectable and a valid option. So it's possible to make the autocomplete a suggestion box.
I'm using ES6 in my projects. But it should be easily adaptable to ES5 code.
myFilter() {
if (!this.query) return this.items;
const
query = this.query.toLowerCase(),
// filter items where the query is a substing
filtered = this.items.filter(item => {
if (!item) return false;
return item.toLowerCase().includes(query);
});
// add search query to filtered list, to make it selectable
// (only if no exact match).
if (filtered.length !== 1 || filtered[0].toLowerCase() !== query) {
filtered.push(this.query);
}
return filtered;
}

get rid of unwanted params in grails pagination

I have a search webpage where user's can filter the search results by a person's ethnicity, as a checkbox group. There are 12 'ethnicity' checkboxes. The params get passed into g:paginate as the following, so that the user can page through the results and preserve what was checked in the ethnicity checkboxes:
<g:paginate controller="search" action="list" total="${resultCount}" params="${params}"/>
What gets output for the links includes a bunch of unnecessary data for each built URL:
2
I'd like the pagination link URLs to be output without all the extra _ethnicity variables that get passed back in the original search post:
2
How can I get the params into the paginate tag without all the extra unnecessary fields? Functionally it works, but the URLs for the paginate get requests are too long and look hideous.
Try this..,.
<g:paginate controller="search" action="list" total="${resultCount}" params="${params.findAll { it.key == 'ethnicity' && it.value }}"/>
it gives you
2
One of the dirty way to achieve what you want is
<g:paginate controller="search" action="list" params="${
params.findAll { a ->
if (a.value instanceof Collection) {
def c = a.value.findAll { b ->
return b
}
if (c) {
return c
}
} else {
return a.value
}
}
}"/>
EDIT:
spock99 answer is much better than mine, one more way is
params="${params.findAll { !it.key.toString().startsWith("_") }}"
Per the previous user, this works to filter out the extra fields, though it is ugly.
params="${params.findAll { a ->
if (!a.key.toString().startsWith("_")) {
return a.value
}
}
}"
EDIT:
Actually a cleaner way is to put this in the controller:
params.keySet().asList().each { if (it.toString().startsWith("_")) params.remove(it) }
Then in the g:paginate you can stick with
params="${params}"

Two related questions on jqGrid column header filters and the advanced filtering dialog

In developing my first ASP.NET MVC 3 app using the jqGrid to display some data, I'm using the column header filters and also allowing for the advanced filter toolbar filtering to be done. Independently these things work pretty well.
First question - Has anyone a solution for communicating the current column header filter settings to the advanced filters?
As an example, a user can filter on the "Ice Cream Name" column, entering a partial name, e.g., "Chocolate", and it'll filter down to "Chocolate Explosion", "Dark Chocolate", etc. - great. What would be nice would be to open the advanced filter and have that "contains 'Chocolate'" column filter automatically populated in the advanced filter. I recognize that the other direction (where someone could AND or OR two values for the same column, e.g. 'Chocolate' OR 'Caramel') becomes problematic but in the other direction, it seems like it might be possible. Perhaps this is just a setting of the grid I'm missing. Anyone solved this?
Second question - I currently can do some filtering with the column header filters, show some result set in the grid and then go into the advanced filter dialog and set up a different filter. That will display the correct results but the column header filters are not cleared, giving the impression that the filtering is not working. How can I reset those column header filters after the use clicks the "Find" button on the dialog?
I find your question very interesting, so I prepared the demo which demonstrate how one can combine Advanced Searching dialog and Toolbar Searching in one grid.
One important, but simple trick is the usage of recreateFilter: true. Per default the searching dialog will be created once and then will be only hide or show. As the result the postData.filters parameter will be not refreshed. After setting recreateFilter: true the problem with filling of the advanced searching dialog with the values from the searching toolbar will be solved. I personally set the default searching options as the following
$.extend(
$.jgrid.search,
{
multipleSearch: true,
multipleGroup: true,
recreateFilter: true,
overlay: 0
}
);
Now to more complex part of the solution is the function refreshSerchingToolbar which I wrote. The function is not so simple, but it's simply in use:
loadComplete: function () {
refreshSerchingToolbar($(this), 'cn');
}
The last parameter is the same parameter which you used as defaultSearch property of the searching toolbar method filterToolbar (the default value is 'bw', but I personally prefer to use 'cn' and set jqGrid parameter ignoreCase: true).
If you fill the advanced searching dialog of the demo with the following field
and click the "Find" button, you will have the following grid:
(I marked the 'Total' column as non-searchable with respect of search: false to show only that all works correctly in the case also)
One can see that all fields of the searching toolbar excepting "Amount" are filled with the values from the searching dialog. The field are not filled because we used "grater or equal" operation instead of "equal". The function refreshSerchingToolbar fills only the elements of the searching toolbar which can be produced by the
Just as a reminder I should mention that in case of the usage of Filter Toolbar it is very important to define searchoptions.sopt options of the colModel. For all non-string column contains (dates, numbers, selects, int, currency) it is extremely important to have 'eq' as the first element of the sopt array. See here and here for details.
If you change the filter of the Advanced Dialog to the following
you will have as expected
At the end I include the code of the refreshSerchingToolbar function:
var getColumnIndex = function (grid, columnIndex) {
var cm = grid.jqGrid('getGridParam', 'colModel'), i = 0, l = cm.length;
for (; i < l; i += 1) {
if ((cm[i].index || cm[i].name) === columnIndex) {
return i; // return the colModel index
}
}
return -1;
},
refreshSerchingToolbar = function ($grid, myDefaultSearch) {
var postData = $grid.jqGrid('getGridParam', 'postData'), filters, i, l,
rules, rule, iCol, cm = $grid.jqGrid('getGridParam', 'colModel'),
cmi, control, tagName;
for (i = 0, l = cm.length; i < l; i += 1) {
control = $("#gs_" + $.jgrid.jqID(cm[i].name));
if (control.length > 0) {
tagName = control[0].tagName.toUpperCase();
if (tagName === "SELECT") { // && cmi.stype === "select"
control.find("option[value='']")
.attr('selected', 'selected');
} else if (tagName === "INPUT") {
control.val('');
}
}
}
if (typeof (postData.filters) === "string" &&
typeof ($grid[0].ftoolbar) === "boolean" && $grid[0].ftoolbar) {
filters = $.parseJSON(postData.filters);
if (filters && filters.groupOp === "AND" && typeof (filters.groups) === "undefined") {
// only in case of advance searching without grouping we import filters in the
// searching toolbar
rules = filters.rules;
for (i = 0, l = rules.length; i < l; i += 1) {
rule = rules[i];
iCol = getColumnIndex($grid, rule.field);
cmi = cm[iCol];
control = $("#gs_" + $.jgrid.jqID(cmi.name));
if (iCol >= 0 && control.length > 0) {
tagName = control[0].tagName.toUpperCase();
if (((typeof (cmi.searchoptions) === "undefined" ||
typeof (cmi.searchoptions.sopt) === "undefined")
&& rule.op === myDefaultSearch) ||
(typeof (cmi.searchoptions) === "object" &&
$.isArray(cmi.searchoptions.sopt) &&
cmi.searchoptions.sopt[0] === rule.op)) {
if (tagName === "SELECT") { // && cmi.stype === "select"
control.find("option[value='" + $.jgrid.jqID(rule.data) + "']")
.attr('selected', 'selected');
} else if (tagName === "INPUT") {
control.val(rule.data);
}
}
}
}
}
}
};
UPDATED: The above code is no more needed in case of usage free jqGrid 4.13.1 or higher. It contains the new default option loadFilterDefaults: true of the filterToolbar, which refreshes the values of the filter toolbar and the filter operations (if searchOperators: true option of filterToolbar is ised) if postData.filters and search: true are set (the filter is applied). Free jqGrid refreshes the filter toolbar on jqGridAfterLoadComplete (if loadFilterDefaults: true are set) or if the event jqGridRefreshFilterValues are explicitly triggered.
I know it's an old post - but if you have multiple grids on the same page the above code can add the filter text to the wrong grid.
Changing this in the first loop in refreshSearchingToolbar, from
control = $("#gs_" + $.jgrid.jqID(cm[i].name));
to
control = $("#gview_"+$grid.attr('id')+" #gs_" + $.jgrid.jqID(cm[i].name));
and this in the second loop from
control = $("#gs_" + $.jgrid.jqID(cmi.name));
to
control = $("#gview_"+$grid.attr('id')+" #gs_" + $.jgrid.jqID(cmi.name));
should do the trick.
Kudos to Oleg

ASP.Net MVC Submit Post Data for Survey

I'm having a hard time figuring out how to collect the data from a FormCollection when submitted for my form which collects the answers for a survey. Specifically my problem is with questions that have multiple choice options(radio buttons) and an other textbox field if the options did not apply.
My survey has the following structure:
QUESTION : [ QuestionId, Text, QuestionType, OrderIndex]
MULTIPLE_CHOICE_OPTIONS: [ MC_OptionId, QuestionId, OrderIndex, MC_Text]
ANSWER: [AnswerId,QuestionId, MC_OptionId (can be null), UserTextAnswer]
QUESTION_TYPES are: [Multiple_Choice, Multiple_Choice_wOtherOption, FreeText or Checkbox]
My view is rendering the form as follows(pseudo code to simplify):
//Html.BeginForm
foreach( Question q in Model.Questions)
{
q.Text //display question text in html
if (q.QuestionType == Multiple_Choice)
{
foreach( MultipleChoice_Option mc in Model.MULTIPLE_CHOICE_OPTIONS(opt => opt.QuestionId == q.QuestionId)
{
<radio name=q.QuestionId value=mc.MC_OptionId />
// All OK, can use the FormCollectionKey to get the
// QuestionId and its value to get the selected MCOptionId
}
}
else if (q.QuestionType == Multiple_Choice_wOtherOption)
{
foreach( MultipleChoice_Option mc in Model.MULTIPLE_CHOICE_OPTIONS(opt => opt.QuestionId == q.QuestionId)
{
<radio name=q.QuestionId value=mc.MC_OptionId />
}
<textbox name=q.QuestionId />
// ****Problem - I can get the QuestionId from the FormCollection Key, but
// I don't know if the value is from the user entered
// textbox or from a MCOptionId***
}
}
<button type="submit">Submit Survey</button>
// Html.EndForm
I was doing it this way so back in the controller action that handles the post back I could read over the FormCollection by key to get the questionId, and the value for each index to get the MCOptionID.
But in the case of the question with radio buttons and a textbox all with the same name key how would I determine if the form data is from the radio button or the text box.
I can see the way I'm doing this breaks because their could be the case where a question (id=1) has a MCOption w/ Id=5 so the radio button has value of 5 and the user enters 5 in the Other textbox. When the form submits I see the formcollection[key="1"] has the value 5 and I can't tell if that is from usertext or the radioButton value referencing a MCOptionId.
Is there a better way to approach this problem, either the db structure, view rendering code or the way the form controls are named? Maybe form collection is not the way to go but I was stumped how to post back and make the model binding work .
Thanks for any help, been going around in circles for something that seems pretty simple.
Consider this small refactoring...
//you're always rendering the radios, it seems?
RenderPartial("MultipleChoice", Model.MULTIPLE_CHOICE_OPTIONS.Where(x =>
x.QuestionId == q.QuestionId));
if (q.QuestionType == Multiple_Choice_wOtherOption)
{
<textbox name="Other|" + q.QuestionId />
}
and within that strongly typed partial view:
//Model is IEnumerable<MultipleChoice_Option >
foreach (MultipleChoice_Option mc in Model )
{
<radio name=mc.Question.QuestionId value=mc.MC_OptionId />
}
It seems your question was around the textbox name; being tied to the question by ID. In your controller, you'll have to explicitly know when to look for any value in the textbox.
string userAnswer = Request.Form["OtherEntry|" + someQuestionID].ToString();

jQuery UI Datepicker - How can i, on select, highlight a particular range of dates?

I want to, when the user selects a date, highlight the following 11 days. The intention is to show a 12-day range selected depending on whatever day was chosen.
I've seen the "date range picker" from http://www.filamentgroup.com/ suggested, but this doesnt really give me the visualization i want, it just lets a user pick a range (from/to) as i understand it.
Any suggestion on how i can realize this?
Cheers
You can use the beforeShowDay event to give a CSS style for the dates you need to highlight.
Code:
$(document).ready(function(){
var selected = null;
$('#datePicker').datepicker({beforeShowDay: function(date) {
if (selected != null && date.getTime() > selected.getTime() &&
(date.getTime() - selected.getTime()) < 12*24*3600*1000) {
return [true, "highlighted"];
}
return [true, ""];
}});
$("#datePicker").datepicker( 'option' , 'onSelect', function() {
str = $(this).val().toString();
selected=$.datepicker.parseDate('mm/dd/yy', str);
console.log(selected);
});
});

Resources