How to make a JIRA Number Field read-only? - jira

As described in the title, I am looking for a smart, safe and efficient way to set a Number Field in JIRA to Read-Only. Below is a short list of approaches, guides and plugins used in an attempt to achieve this.
Installed and deployed the Behaviours Plugin
This resulted in form permission errors all over JIRA setting some of the most basic and editable fields to non-writeable. Further investigation revealed that this is a known issue that will not be fixed anytime soon.
I have gone up and down the options for JIRA's existing Field Behaviour and it simply does not offer the option to set a field to read-only.
Hiding is not an option, as the field needs to be visible (more about that below).
A potential option would be to create a new Screen Scheme that simply excludes this field from the edit screen.
Associating new Screen Schemes with our current project would be a small disaster as many other projects are dependent and shared. Hence making the field read-only or admin-writeable-only would be a much better solution in this instance.
Regarding the Custom Field:
I created a post function in the workflow of our current project that will increase a Custom Number Field by increments of 1 every time an issue/task/bug is reopened. In essence, I am tracking the numbers of reopens. Which brings me to the reason for my read-only requirement. Developers shouldn't be able to change the value of this field as it would throw off statistics.

You can use jquery to make the field read only, add to the field description :
<script type="text/javascript">
AJS.$(document).ready(function() {
AJS.$("#customfield_10000").attr("readonly", true);
});
</script>
change customfield_10000 to your custom field id. You can find this id by viewing the issue edit page source and checking which id does it have.
Check out this and this answers and this for more details.
[UPDATE]
To disable the hover-to-edit function as well, you can add the following script to jira's Announcement Banner , this way it will run on every screen:
<script type="text/javascript">
AJS.$(document).ready(function() {
AJS.$("#customfield_10000").attr("readonly", true);
AJS.$("#customfield_10000").removeClass("editable-field inactive");
AJS.$("#customfield_10000 .icon-edit-sml").remove();
});
</script>

Stopping inline editing from working is trickier it seems. What stopped the Behaviours plugin working for you, do you have a link to the known issue? The one option you haven't listed is to create a new custom field type that extends the familiar Number custom field type but in its velocity template restricts who can edit the field. This kind of customization is documented at https://developer.atlassian.com/display/JIRADEV/Creating+a+Custom+Field+in+JIRA and also in Practical JIRA Plugins (O'Reilly)

Use the "disabled" keyword in your form item. E.g.
Code:
<input type="text" name="foo" value="bar" disabled>

Related

Clicking checkbox using capybara

Currently I have a checkbox wrapped by a label.
<label for="exercise_form_division_ids_34">
<input class="check_boxes optional division-checkboxes" type="checkbox" value="34" name="form[division_ids][]" id="exercise_form_division_ids_34"> Technology
</label>
In my integration test I tried to use
within '.organizations' do
find("label[for='exercise_form_division_ids_34").click
end
OR
check "exercise_form_division_ids_#{department.id}", allow_label_click: true
But I still get this nable to find visible checkbox "calltree_exercise_form_division_ids_2" that is not disabled
Unable to find visible checkbox "exercise_form_division_ids_" that is not disabled
With the limited info provided you have a few potential possibilities.
The label/checkbox aren't actually inside an element with the class of the organizations on the page.
The error Unable to find visible checkbox "exercise_form_division_ids_" that is not disabled shows that no id is actually getting inserted into your selector which would tend to indicate that department isn't actually persisted in your test.
You may be assuming 34 is the correct id based on what it is in your dev environment but that may not be what it is in your test environment.
To narrow down the possibilities the first thing to do would be to grab a screenshot in your with test with page.save_and_open_screenshot (assuming you're using a driver which supports screenshots) and make sure there is actually a visible checkbox on the page. If not, you're probably not creating the required objects in the DB prior to your test starting.
Secondly look at the page in your browser and make sure the elements visible on the screen are actually the checkbox and/or the label. If both label & checkbox are being hidden and replaced with some JS widget then you'd need to interact with whatever elements the widget creates in the page (just like a user would). If only the checkbox is being hidden via JS/CSS but the label is visible then
check('Technology', allow_label_click: true) # check matching on label text
should work.

Changing kendo-dateinput placeholder for Kendo Angular2

Is there a way to change or simply remove the placeholder of the Kendo UI - Angular 2 dateinput control?
Right now, when empty, it reads "day/month/year" and I need to, at least, remove the localized literals.
Thank you very much,
Dimitris
UPDATE: With the latest changes in the DateInput (as of v1.4.0) two additional properties were added:
placeholder - display text hint (related Github issue)
formatPlaceholder - control description of the format sections (Github issue)
With those available, we can easily hide or modify the displayed format description:
<kendo-datepicker [placeholder]="Enter date..." [formatPlaceholder]="short" />
Here is a plunker demo that demonstrates those new properties:
http://plnkr.co/edit/XYmwDjkpp7Mb4txlmc2L?p=preview
Indeed, the DateInput component displays the localized format value once empty. That being said, its value is controlled by the component date format. Its behavior is similar to the Chrome's <input type="date" />.
I'm afraid that the placeholder cannot be set to a custom text.
I think that it will be best to share your request in the Kendo UserVoice portal:
http://kendoui-feedback.telerik.com/forums/555517-kendo-ui-for-angular-feedback

Show custom fileds based on other custom field value on CREATE ISSUE screen

I'm implementing a help desk in JIRA where I have two drop downs - both 'single value select' for Category and Sub-category.
For example,
I have following Categories:
Content Development
Events
Design
And each category has a list of sub-categories within them. For example, Design will have following list of options
Event Collateral
Branding
Business Cards
By default, ONLY Category dropdown should be displayed on the CREATE ISSUE screen.
When user selects one of the categories, corresponding sub-category drop-down should be displayed on the CREATE ISSUE screen AND that sub-category dropdown should be MANDATORY field.
I looked up for possible solution at the following links:
https://confluence.atlassian.com/display/JIRA052/Displaying+a+Field+Based+on+Another+Field+Selection
https://confluence.atlassian.com/display/JIRA/Displaying+a+Field+Based+on+Another+Field+Selection
https://answers.atlassian.com/questions/217176/show-hide-custom-field-depend-on-another-custom-field-value
The first two links basically suggests the same solution - that is to put a JAVASCRIPT in the description field of the custom field and the same is suggested on many other blogs on this issue. They all give this very same example.
However this is not working for me. When I put any JAVASCRIPT in the description of the custom-field, it runs immediately upon saving - on the Field Configuration screen. For example, I just put a following JAVASCRIPT in the description and I got the alert right away (on the Field Configuration screen).
<script type="text/javascript">
alert('hi');
</script>
However, I do not get any alert on the CREATE ISSUE screen. So, not sure if I am missing anything here. Please advise if I'm looking in the right direction.
The 3rd link, suggests to create a plugin from the JIRA machine. However, I do not have access to that machine, I just have admin access to JIRA.
Is there any feasible way to achieve it via default JIRA configurations/external plugins which are ready-to-use?
My JIRA version is: 6.1.4
I have used Java script in custom fields in JIRA 6.0.8,JIRA 6.2.4 and JIRA 6.4.8 as well, so I think it should definitely work in JIRA 6.1.4.
You only need to put java script in sub category custom field as below:
For example for Design ->
Replace customfield_ID1 with custom id of Category Custom field and customfield_ID2 with custom id of Sub Category Design Custom field
<script type="text/javascript">
jQuery(document).ready(function($) {
JIRA.bind(JIRA.Events.NEW_CONTENT_ADDED, function (e, context) {
callChangeFunction();
});
callChangeFunction();
function callChangeFunction(){
showHidField();
// dropdown custom field change function
$("#customfield_ID1").change(function() {
showHidField();
});
}
function showHidField(){
//drop down field selected value
var dropDownFieldval =$.trim($("#customfield_ID1 :selected").text());
//test field1
$("#customfield_ID2").closest('div.field-group').hide();
if(dropDownFieldval == 'Design'){
$("#customfield_ID2").closest('div.field-group').show();
}else
$("#customfield_ID2").closest('div.field-group').hide();
}
});
</script>
Above will show or hide the field, please ensure that Category and Subcategory custom fields both are on same screen (Ex: Create Screen)
Now in order to make them Mandatory, you need to write that code as validator on create transition in Project Workflow as below:
import com.atlassian.jira.issue.customfields.option.LazyLoadedOption;
LazyLoadedOption selOption = issue.getCustomFieldValue (customFieldManager.getCustomFieldObject('customfield_ID1'));
(selOption.getValue()=='Design' && cfValues[Name of design Sub Category field#'])|| selOption.getValue()=='Events';
Make sure that you have Behaviour Plugin installed to get simple script validator
Hope this helps!
Priyanka Lavania

making unobtrusive validation work when using Select2 ASP.NET MVC

Select boxes converted to Select2, do not automatically integrate with unobtrusive validation mechanism in ASP.NET MVC framework.
For example, on a form which contains a regular select box (marked as required in model definition), submitting the form while no options have been selected in the select box, will cause the border and background of the select box to take a reddish color, and by using #Html.ValidationMessageFor, error messages, if any, can be displayed beside the box. However if the select box is converted to a Select2 component, then none of the mentioned features work any more. Even the validation error message will not show up.
It seems that the reason for even the validation error message not showing, is because Select2 changes the display CSS property of the original select box to none (display:none), and I guess the unobtrusive validation script does not bother generating error messages for invisible fields.
Any ideas / solutions?
This issue isn't really specific to Select2, but rather to the jQuery unobtrusive validator.
You can turn on validation for hidden fields as highlighted in this answer.
$.validator.setDefaults({
ignore: ''
});
As the comments noted, it didn't work inside an anonymous callback function within $(document).ready(). I had to put it at the top level.
I've run into similar issues with the select2 plugin. I don't know exactly which features you're using specifically, but in my experience, when you set an element as a select2 in the document.ready event, the plugin will change some of the element's attributes on the fly (inspect one of the elements after your page has finished loading - oftentimes you'll see the id and class properties are different than what you're seeing when you view source).
It's difficult to offer more without actually seeing the code, but here's a few ideas to get you started:
First off, obviously make sure you have the a link to your select2.css stylesheet in the header.
Then, since you're talking about form submissions, I'd recommend you examine whether or not you're getting a full postback or submitting via AJAX (if you're using jQueryMobile, you're using AJAX unless you override it in the jquerymobile.js file or set a data-ajax="false" in your form attributes). You can just look at the value returned by Request.IsAjaxRequest() for this. Obviously if you're submitting via ajax, you won't hit the document.ready event and the select2 won't initialize properly and you'd need to figure out a way around that. Try refreshing the page after the submit and see if it renders the select2 component.
Then I'd suggest examining the elements and see if they're not behaving like you'd expect because you're actually trying to work with classes that the plugin has reassigned at runtime. You can either just adjust your logic, or you can dig into the select2 code itself and change the behavior - it's actually fairly well-documented what the code is doing, and if you hop on the Google group for select2, Igor is usually pretty quick to follow up with questions.
like this
$('select').on('select2:select', function (evt){
$(this).blur();
});
$('body').on('change', 'select.m-select2', function () {
$(this).blur();
})

How can I manipulate a form / inputs to be ignored when a form is submitted

I'm using ExpressionEngine and SafeCracker along with Ajax (plugin: jquery.form.js - http://jquery.malsup.com/form/).
Best I can tell, SafeCracker will only allow for updating a single entry at a time. However, the UI / UX necessitates that a list be displayed. I've proof of concept'ed an entry by entry on-demand form. That is, click a particular edit link next to each entry and a snippet of jquery creates a form along with displaying a submit button. Click submit and that single entry updates. The inputs don't exist until the Update link is clicked
What I would prefer to do, if possible, is to create the non-form and form versions of each entry as the page is renbered and use some sort of toggle to display one or the other. Again, doable. Then, when I click the Edit link I'd add the necessary attributes to the input so that entry's form elements will be read but the other (display: none) elements for the other entries will be ignored. I'm thinking (out loud) that if I add the attr("name", some-value) that would work. That is, an input with no name will be ignored.
Yes, I can test this and I will. However, even if it works I'm not sure if it's a best practice and/or there's a more ideal way of accomplishing my ends. I'm here looking for validation and/or additional expertise and input.
Thanks in advance.
Just set disabled property to inputs and they will excluded from Form submission, whatever input fields are hidden or visible. Different jQuery methods, like submit() and serialize() follow specification of HTML 4 and exclude all disabled controls of a forms. So one way is to set
$('your_input').prop('disabled', true);
or ,
$('your_input').attr('disabled', 'disabled');
Check following link:
http://www.w3.org/TR/html401/interact/forms.html#successful-controls
Also, you may use a general button instead of a submit, as result you can handle click event on it and within that event you can make exclusion, validation, manipulation on values and what ever you like.
You can put a disabled attribute on them server side or set the property via jQuery:
$(".hidden input").prop("disabled", true);

Resources