Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Word.Range.insertContentControl(type) will always insert RichText content control regardless of type argument #5407

Closed
Metab0i opened this issue Feb 17, 2025 · 8 comments
Assignees
Labels
Area: Word Issue related to Word add-ins Needs: attention 👋 Waiting on Microsoft to provide feedback Needs: triage 🔍 New issue, needs PM on rotation to triage ASAP

Comments

@Metab0i
Copy link

Metab0i commented Feb 17, 2025

Article URL

Describe the problem
Regardless of what API consumer passes to Word.Range.insertContentControl(…), it will always insert a RichText content control.

What was attempted to arrive at this conclusion:

  • Attempted to use a member of Word.ContentControlType enum - didn’t work
  • Attempted to pass a string argument (“CheckBox”, “DropDownList”, “ComboBox”) - didn’t work
  • Ran isolated experiment - didn’t work

API version: ^1.1.86

Screenshots
-/-

@microsoft-github-policy-service microsoft-github-policy-service bot added the Needs: triage 🔍 New issue, needs PM on rotation to triage ASAP label Feb 17, 2025
@AlexJerabek
Copy link
Collaborator

Hi @Metab0i,

Thank you for reporting this issue. @ElizabethSamuel-MSFT, could you please investigate?

@AlexJerabek AlexJerabek added Area: Word Issue related to Word add-ins Needs: attention 👋 Waiting on Microsoft to provide feedback and removed Needs: triage 🔍 New issue, needs PM on rotation to triage ASAP labels Feb 18, 2025
@ElizabethSamuel-MSFT
Copy link
Contributor

@Metab0i Thanks for reaching out. Can you let us know what client and build/version of Word is being used? Thanks.

@ElizabethSamuel-MSFT ElizabethSamuel-MSFT added Needs: author feedback Waiting for author (creator) of Issue to provide more info and removed Needs: attention 👋 Waiting on Microsoft to provide feedback labels Feb 18, 2025
@ElizabethSamuel-MSFT
Copy link
Contributor

@Metab0i The following are a few samples you can try in our Script Lab tool that use Range.insertContentControl(type).

Also let us know the outcome of your trying these out.

Thanks.

@Metab0i
Copy link
Author

Metab0i commented Feb 19, 2025

@ElizabethSamuel-MSFT, thank you for a prompt response.

"... what client and build/version of Word is being used?"
MSO (Version 2501 Build 16.0.18429.20132) 64-bit

"...let us know the outcome of your trying these out."
HTML

html body...
    <div class="container" style="display: flex; flex-direction: column; gap: 0.5rem;">
      <button id="insertCheckBoxCC" type="button" class="btn btn-primary" style="font-size: x-small;">Insert Checkbox Content Control</button>
      <button id="insertComboBoxCC" type="button" class="btn btn-primary" style="font-size: x-small;">Insert Combo-box Content Control</button>
      <button id="insertDropdownListCC" type="button" class="btn btn-primary" style="font-size: x-small;">Insert Dropdown-List Content Control</button>
    </div>

Script

Office.onReady(async (info) => {
      if(info.host !== Office.HostType.Word) return console.error('Wrong Host Enviornment. Expected Microsoft Word.');

      document.querySelector('#insertCheckBoxCC')
        .addEventListener("click", async function(_evnt){
          await Word.run(async (context) => {
            let selection = context.document.getSelection();
            selection.getRange(Word.RangeLocation.end).insertContentControl(Word.ContentControlType.checkBox);
            await context.sync();

            console.log("Check-box content control inserted at the end of the selection.");
          });
        })
      
      document.querySelector('#insertComboBoxCC')
        .addEventListener("click", async function(_evnt){
          await Word.run(async (context) => {
            let selection = context.document.getSelection();
            selection.getRange(Word.RangeLocation.end).insertContentControl(Word.ContentControlType.comboBox);
            await context.sync();

            console.log("Combo-box content control inserted at the end of the selection.");
          });
        })

      document.querySelector('#insertDropdownListCC')
        .addEventListener("click", async function(_evnt){
          await Word.run(async (context) => {
            let selection = context.document.getSelection();
            selection.getRange(Word.RangeLocation.end).insertContentControl(Word.ContentControlType.dropDownList);
            await context.sync();

            console.log("Dropdown list content control inserted at the end of the selection.");
          });
        })
}

Outcome:

Media1.mp4

@microsoft-github-policy-service microsoft-github-policy-service bot added Needs: attention 👋 Waiting on Microsoft to provide feedback and removed Needs: author feedback Waiting for author (creator) of Issue to provide more info labels Feb 19, 2025
@Metab0i
Copy link
Author

Metab0i commented Feb 19, 2025

Image

For additional context, here are properties of a content control that was supposed to be a Combo box; There's no list properties section

@ElizabethSamuel-MSFT
Copy link
Contributor

When I tried out your code, I got the following behavior.

Image

I'll transfer this to the office-js repo for the product team to investigate further.

Thanks.

@ElizabethSamuel-MSFT ElizabethSamuel-MSFT transferred this issue from OfficeDev/office-js-docs-reference Feb 19, 2025
@ElizabethSamuel-MSFT ElizabethSamuel-MSFT removed their assignment Feb 19, 2025
@ElizabethSamuel-MSFT ElizabethSamuel-MSFT added Needs: triage 🔍 New issue, needs PM on rotation to triage ASAP and removed Needs: attention 👋 Waiting on Microsoft to provide feedback labels Feb 19, 2025
@penglongzhaochina
Copy link

Hi @Metab0i ,

I tried the three insert content control function type. When I inserted the DropDown list content controls it shows below control. It's expected.

Image
When I inserted the Checkbox list content controls it shows below control. It's expected.

Image

When I inserted the Checkbox list content controls it shows below control. It's expected.

Image

All the above content control added from Api side is same as the content control added from the developer tab like below picture:

Image

About the content control properties dialog, it doesn't show the specific content control properties when you selected a content control and open the dialog, the same as the behavior when you added a content control from the developer tab. Feel free to add more comments here.

@penglongzhaochina penglongzhaochina added the Needs: author feedback Waiting for author (creator) of Issue to provide more info label Feb 20, 2025
@Metab0i
Copy link
Author

Metab0i commented Feb 20, 2025

I see.. From the looks of it, problems seems to be contained to my environment; I will investigate and see if I can find the cause of this. Thank you for your time everyone

@microsoft-github-policy-service microsoft-github-policy-service bot added Needs: attention 👋 Waiting on Microsoft to provide feedback and removed Needs: author feedback Waiting for author (creator) of Issue to provide more info labels Feb 20, 2025
@Metab0i Metab0i closed this as completed Feb 20, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area: Word Issue related to Word add-ins Needs: attention 👋 Waiting on Microsoft to provide feedback Needs: triage 🔍 New issue, needs PM on rotation to triage ASAP
Projects
None yet
Development

No branches or pull requests

5 participants