Cardinality Logic Adds 1 too many map points

Created on 30 November 2023, about 1 year ago
Updated 2 December 2023, about 1 year ago

Problem/Motivation

I'm using a geolocation field with a cardinality of 10. When adding points via clicking the map (and using the geocoding as well) with a cardinality of 10, for example, you can add an 11th point before the map refuses to add any more. I expect it to only allow me to add 10 points. However, it correctly doesn't add an 11th Lat/Lng fieldset (So if I save the map, it correctly only has 10 points) so it is a purely front end issue it seems.

Steps to reproduce

  • Create a geolocation field with a cardinality that is over 1 but not unlimited. I used 10.
  • Click the map and/or use the geocoding search field to add 10 points.
  • Add another Point
  • You will see an 11th marker on the map
  • Add a 12th point. You will see it refuse to add another point (and an error in the console) This is the expected behavior when I add an 11th point.

Proposed resolution

I believe this is due to The following code in the geolocation-widget-api.js file located in the /js folder:

getNextDelta: function () {
      if (this.cardinality === 1) {
        return 0;
      }

      var delta = Math.max(
        this.getNextEmptyInputDelta(),
        this.getNextPendingDelta()
      );
      if (delta > this.cardinality && this.cardinality > 0) {
        console.error("Cannot add further geolocation input.");
        return false;
      }
      return delta;
    },

specifically the line

if (delta > this.cardinality && this.cardinality > 0) {

I believe simply changing this to

if (delta >= this.cardinality && this.cardinality > 0) {

Will fix this issue.

🐛 Bug report
Status

Fixed

Version

3.0

Component

Javascript General / Frontend

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

Production build 0.71.5 2024