You could write some javascript to achieve this. I once did this though the repeatable property didn't have an own jelly file. I'm no javascript expert though there might be a better way to get the elements. The risk would be if there are other elements that have the same name, then you could get false positives.

<f:repeatable field="objectWithUniqueName" var="f" header="Test">
  <f:entry field="uniqueId">
    <f:textbox onchange="checkForDuplicates()" onkeyup="checkForDuplicates()"/>
  </f:entry>
</f:repeatable>
<div id="uniqueId-error" class="error" style="display:none"></div>

function StringSet()
{
  var setObj = {}, val = "true"

  this.add = function(str)
  {
    setObj[str] = val
  }

  this.contains = function(str)
  {
    return setObj[str] === val
  }
}

function checkForDuplicates()
{
  var uniqueIds = document.getElementsByName("_.uniqueId")
  var errorElement = document.getElementById("uniqueId-error")
  var uniqueIdSet = new StringSet()
  var hasError = false
  for (i=0; i<locationIds.length; i++)
  {
    if (uniqueIdSet.contains(uniqueIds[i].value)
    {
      hasError = true
      errorElement.style.display = "block"
      errorElement.innerHTML = "Duplicate ID: " + uniqueIds[i].value
      break;
    }
  }
  if (!hasError)
  {
    errorElement.style.display = "none"
  }
}



On 16.02.2018 13:04, Joachim Kuhnert wrote:

Hello,

I would like to check if the content of a text field of a repeatable property is unique (in the context of the project) when the user enters a text.

Let’s say I have a Plugin with a structure like that:

class Parent extends Builder {

   List<Child> objectsWithUniqueName;

}

class Child implements Describable<Child> {

   String name;  // has to be unique in project

   public static final class DescriptorImpl extends Descriptor<JenkinsConfiguration> {

      FormValidation doCheckName(@QueryParameter String value, @AncestorInPath AbstractProject project) {

          // TODO: check uniqueness of name

      }

   }

}

<f:entry>

<f:repeatableProperty field="objectsWithUniqueName" header="Unique Child" noAddButton="false" />

</f:entry>

I am able to get the List of  Child-Objects of the Project that were saved the last time via the AbstractProject (cast to Project and use getBuilkders()-Method). Since the user is currently configuring the project he could have made cahnged (changed the name value of different Children or added/removed Children) there could be name clashes that are not yet saved or already solved.

Is it possible to get the currently not yet stored values for the siblings of  form?

Best Regards,

Joachim

---------------------------------------------------

Joachim Kuhnert

fon:  +49 30 394 09 683 39

mail: [email protected]

PikeTec GmbH, Waldenserstr. 2-4, 10551 Berlin

Management: Eckard Bringmann, Andreas Krämer, Jens Lüdemann

Location of the company: Berlin (Germany)

Trade register: Amtsgericht Berlin HRB 105491 B

Website: www.piketec.com <www.piketec.com>

--
You received this message because you are subscribed to the Google Groups "Jenkins Developers" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected] <mailto:[email protected]>. To view this discussion on the web visit https://groups.google.com/d/msgid/jenkinsci-dev/4e635b05567d409485c8eb4e61e695f7%40piketec.com <https://groups.google.com/d/msgid/jenkinsci-dev/4e635b05567d409485c8eb4e61e695f7%40piketec.com?utm_medium=email&utm_source=footer>.
For more options, visit https://groups.google.com/d/optout.

--
You received this message because you are subscribed to the Google Groups "Jenkins 
Developers" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/jenkinsci-dev/5cd58e20-c956-d9df-a0da-a3ef253d0767%40gmx.de.
For more options, visit https://groups.google.com/d/optout.

Reply via email to